version 16
clear all
cd "D:\RFS RedX"
set more off
set varabbrev off, perm
capture log close _all
log using logs\RXLog.smcl, append name(mainlog)
local lognum = string(clock("$S_DATE $S_TIME","DMY hms"), "%tcCCYY_NN_DD_HH_MM_SS")
log using "logs\sublogs\RXLog_`lognum'.smcl", append name(secondarylog)
	
	use importparcelid propertyzip propertyaddresslatitude propertyaddresslongitude state propertyfullstreetaddress propertyaddressunitdesignator propertyaddressunitnumber using RX_ZTRAX_Addresses, clear
		
		preserve
			
				rename propertyfullstreetaddress z_street
				rename state z_state
				rename propertyzip z_zip
				rename propertyaddresslatitude z_lat
				rename propertyaddresslongitude z_lon
				
				replace z_street=z_street+propertyaddressunitdesignator+propertyaddressunitnumber
					drop propertyaddressunitdesignator propertyaddressunitnumber
					
				replace z_street = subinstr(z_street," ","",.)
				replace z_street = strupper(z_street)
					compress z_street
				
				drop if z_state=="" | z_state=="GU"
					drop z_state
				destring z_zip, replace force
				drop if z_zip==.
				drop if z_street==""
				
				gen firstcharnumeric = substr(z_street,1,1)
				destring firstcharnumeric, replace force
				drop if firstcharnumeric==. | firstcharnumeric==0
				drop firstcharnumeric
				replace z_lon=-abs(z_lon)
				replace z_lat=abs(z_lat)
				
				replace z_street = strupper(z_street)
				gen z_street_short = z_street
				
				replace z_street_short = subinstr(z_street_short," PT","",.)
				replace z_street_short = subinstr(z_street_short," DR","",.)
				replace z_street_short = subinstr(z_street_short," ST","",.)
				replace z_street_short = subinstr(z_street_short," AVE","",.)
				replace z_street_short = subinstr(z_street_short," RD","",.)
				replace z_street_short = subinstr(z_street_short," CT","",.)
				replace z_street_short = subinstr(z_street_short," TRCE","",.)
				
				replace z_street_short = subinstr(z_street_short," POINT","",.)
				replace z_street_short = subinstr(z_street_short," DRIVE","",.)
				replace z_street_short = subinstr(z_street_short," STREET","",.)
				replace z_street_short = subinstr(z_street_short," AVENUE","",.)
				replace z_street_short = subinstr(z_street_short," ROAD","",.)
				replace z_street_short = subinstr(z_street_short," COURT","",.)
				replace z_street_short = subinstr(z_street_short," TERRACE","",.)
				
				replace z_street_short = subinstr(z_street_short," ","",.)
				
				drop z_street
				
				duplicates drop

				sort z_zip
				compress
			save RFSRX_Addresses_Z_Short, replace
			
		restore
	
		drop state propertyfullstreetaddress propertyaddressunitdesignator propertyaddressunitnumber
		
		rename propertyzip z_zip
		rename propertyaddresslatitude z_lat
		rename propertyaddresslongitude z_lon
		
		destring z_zip, replace force
		drop if z_zip==.
		
		replace z_lat = round(z_lat,0.00001)
		replace z_lon = round(z_lon,0.00001)
		
		replace z_lat=abs(z_lat)
		replace z_lon=-abs(z_lon)
		
		replace z_lat=. if z_lat>90 | z_lat<-90
		replace z_lon=. if z_lon>180 | z_lon<-180
		
		drop if z_lat==. | z_lon==.
		
		sort z_zip
		compress
	save RFSRX_ZTS_ZTRAX_Props, replace
	
	use z_zip using RFSRX_ZTS_ZTRAX_Props, clear
		gen double address=_n
		collapse (min) firstaddress=address (max) lastaddress=address, by(z_zip)
			rename z_zip zip
		compress
	save RFSRX_PCS_ZWZipIndex, replace
	
	use createdate ams_id street city state zip latitude longitude using RX_Leads, clear

		rename createdate createdatetime
		
		duplicates drop
			
		preserve

			save RFSRX_Addresses_REDX, replace
		
		restore
	
		rename street rx_street
		rename city rx_city
		rename state rx_state
		rename zip rx_zip
		rename latitude rx_lat
		rename longitude rx_lon
		
		replace rx_street = subinstr(rx_street," ","",.)
		replace rx_street = strupper(rx_street)
			compress rx_street
	
		drop if rx_state==""
		drop if rx_zip==.
		drop if rx_street==""
		drop createdatetime
		gen firstcharnumeric = substr(rx_street,1,1)
		destring firstcharnumeric, replace force
		drop if firstcharnumeric==. | firstcharnumeric==0
		drop firstcharnumeric
		replace rx_lon=-abs(rx_lon)
		replace rx_lat=abs(rx_lat)
		replace rx_lat=. if rx_lat>90 | rx_lat<-90
		replace rx_lon=. if rx_lon>180 | rx_lon<-180
			drop rx_city

		replace rx_street = strupper(rx_street)
		gen rx_street_short = rx_street
		
		replace rx_street_short = subinstr(rx_street_short," PT","",.)
		replace rx_street_short = subinstr(rx_street_short," DR","",.)
		replace rx_street_short = subinstr(rx_street_short," ST","",.)
		replace rx_street_short = subinstr(rx_street_short," AVE","",.)
		replace rx_street_short = subinstr(rx_street_short," RD","",.)
		replace rx_street_short = subinstr(rx_street_short," CT","",.)
		replace rx_street_short = subinstr(rx_street_short," TRCE","",.)
		
		replace rx_street_short = subinstr(rx_street_short," POINT","",.)
		replace rx_street_short = subinstr(rx_street_short," DRIVE","",.)
		replace rx_street_short = subinstr(rx_street_short," STREET","",.)
		replace rx_street_short = subinstr(rx_street_short," AVENUE","",.)
		replace rx_street_short = subinstr(rx_street_short," ROAD","",.)
		replace rx_street_short = subinstr(rx_street_short," COURT","",.)
		replace rx_street_short = subinstr(rx_street_short," TERRACE","",.)
		
		replace rx_street_short = subinstr(rx_street_short," ","",.)
		
		drop rx_street
		
		sort ams_id
		
		gen double ams_id_short=_n
			order ams_id_short, after(ams_id)
		
		preserve
				keep ams_id ams_id_short
			save RFSRX_Addresses_RX_Short_amslookup, replace
		restore
		
		drop ams_id
		sort rx_zip
		
		compress
	save RFSRX_Addresses_RX_Short, replace
	
	use RFSRX_Addresses_Z_Short, clear
		gen double address=_n
		collapse (min) firstaddress=address (max) lastaddress=address, by(z_zip)
			rename z_zip zip
		compress
	save RFSRX_ZillowZipAddresses, replace
	
	use RFSRX_Addresses_RX_Short, clear
		keep rx_zip
		rename rx_zip zip
		gen counter=1
		collapse (sum) counter, by(zip)
		merge 1:1 zip using RFSRX_ZillowZipAddresses
			keep if _merge==3
			drop _merge
		set seed 19851985
		gen rnum=runiform()
		sort rnum
		drop rnum
		compress
	save RFSRX_Match_Zips, replace
	
	
	
	local batches = 16
	forvalues batch = 1(1)`batches' {
	
		frame create RXListings2

		frame create RXListings
		frame change RXListings
		
		use RFSRX_Addresses_RX_Short, clear
		
		frame create MatchResults
		
		frame create Zips
		frame change Zips
		
		use RFSRX_Match_Zips, clear

			local N = _N
			
			local last = floor(min(`batch'*`N'/`batches',`N'))
			local first = floor(min(`batch'*`N'/`batches'+1-`N'/`batches',`N'))
			
			if `first'==`last' & `last'==`N'{
				disp "You did too many batches!!"
				disp "if there are exactly 1000*n+1 zips then you need to do the last row manually"
				crashmenow
			}
			
			forvalues i = `first'/`last' {
				frame change Zips
				
				local zip = zip[`i']
				local firstaddress = firstaddress[`i']
				local lastaddress = lastaddress[`i']
				
				disp `zip'
				disp "Doing zip number `i' for batch `batch' going from `first' to `last' out of total `N'"
				disp "From `firstaddress' to `lastaddress'"
				display c(current_time)
				
				frame drop RXListings2 
				frame copy RXListings RXListings2
				frame change RXListings2
				
					keep if rx_zip==`zip'
						drop rx_zip rx_state
						gen matchpoint = 1
						compress
					save RFSRX_tempziptrans_`batch', replace
				
				frame change default
					
					use in `firstaddress'/`lastaddress' using RFSRX_Addresses_Z_Short, clear
						drop z_zip
						gen matchpoint = 1
						compress
						
					joinby matchpoint using RFSRX_tempziptrans_`batch'
					drop matchpoint
			
					if _N>0{
						
						count if (z_lat<. & z_lon<. & rx_lat<. & rx_lon<.)
						
						if r(N)>0{
							timer on 1
							geodist z_lat z_lon rx_lat rx_lon, gen(geo_dist) sphere miles
							timer off 1
							timer list
							timer clear
						}
						else {
							gen geo_dist=.
						}
						
						timer on 2
						strdist z_street_short rx_street_short, gen(str_dist) maxdist(10)
						timer off 2
						timer list
						timer clear
		
						timer on 3
						sort ams_id_short
						timer off 3
						timer list
						timer clear
						
						timer on 4
						by ams_id_short, sort: egen topgeodist=rank(geo_dist), track
						by ams_id_short, sort: egen topstrdist=rank(str_dist), track
						timer off 4
						timer list
						timer clear
						
						keep if str_dist<5 | topstrdist<=10 | topgeodist<=10 | geo_dist<=.1
					
					if _N>0{
					
						save RFSRX_tempresults_`batch', replace
						frame change MatchResults
							append using RFSRX_tempresults_`batch'
							if mod(`i',10)==0 {
													
								save RFSRX_Matches_`batch', replace
								
							}

						}
					}
				}
		
				frame change MatchResults
					compress
				save RFSRX_Matches_`batch', replace
				
				frame change default
				frame drop MatchResults
				frame drop Zips
				frame drop RXListings
				frame drop RXListings2
		
		}
		
			clear
		forvalues batch = 1/16 {
		
			append using RFSRX_Matches_`batch'
		
		}
		
			
			
			keep if str_dist<5 | topstrdist<=10 | topgeodist<=10 | geo_dist<=.01
		
			compress
		save RFSRX_Matches, replace
				
	
		use importparcelid using RFSRX_Matches, clear
			duplicates drop
		save RFSRX_FoundParcels, replace
		
		
		use RX_ZTRAX_Addresses, clear
			merge m:1 importparcelid using RFSRX_FoundParcels
				keep if _merge==3
				drop _merge
				compress
		save RFSRX_Addresses_ZTRAX_FoundParcels, replace
	
	
		use RFSRX_Matches, clear
			
			merge m:1 ams_id_short using RFSRX_Addresses_RX_Short_amslookup
				drop if _merge==2
				drop _merge ams_id_short
			
			drop rx_lat rx_lon
			
			joinby ams_id using RFSRX_Addresses_REDX
				rename street rx_street
				rename city rx_city
				rename state rx_state
				rename zip rx_zip
				rename latitude rx_lat
				rename longitude rx_lon
				order ams_id importparcelid createdatetime
			
			joinby importparcelid using RFSRX_Addresses_ZTRAX_FoundParcels
				rename propertyfullstreetaddress z_street
				rename propertycity z_city
				rename state z_state
				rename propertyzip z_zip
				drop propertyhousenumber propertyhousenumberext propertystreetpredirectional propertystreetname propertystreetsuffix propertystreetpostdirectional fips propertyaddressmatchcode propertyaddresslatitude propertyaddresslongitude
				replace z_street=z_street+propertyaddressunitdesignator+propertyaddressunitnumber
					drop propertyaddressunitdesignator propertyaddressunitnumber propertyzip4 propertyaddressunitdesignator propertyaddressunitnumber propertystate
					order z_street, after(rx_street)
					order z_city, after(rx_city)
					order z_state, after(rx_state)
					order z_zip, after(rx_zip)
					order z_lat z_lon, after(rx_lon)
			
			replace z_street = strupper(z_street)
			replace rx_street = strupper(rx_street)
			
			gen rx_street_numeric = rx_street_short
				replace rx_street_numeric = subinstr(rx_street_numeric,"A","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"B","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"C","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"D","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"E","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"F","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"G","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"H","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"I","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"J","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"K","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"L","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"M","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"N","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"O","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"P","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"Q","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"R","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"S","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"T","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"U","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"V","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"W","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"X","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"Y","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"Z","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"/","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"#","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,"-","",.)
				replace rx_street_numeric = subinstr(rx_street_numeric,".","",.)
			gen rx_street_alpha = rx_street_short
				replace rx_street_alpha = subinstr(rx_street_alpha,"0","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"1","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"2","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"3","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"4","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"5","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"6","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"7","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"8","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"9","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"/","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"#","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,"-","",.)
				replace rx_street_alpha = subinstr(rx_street_alpha,".","",.)
			gen z_street_numeric = z_street_short
				replace z_street_numeric = subinstr(z_street_numeric,"A","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"B","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"C","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"D","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"E","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"F","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"G","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"H","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"I","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"J","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"K","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"L","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"M","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"N","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"O","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"P","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"Q","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"R","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"S","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"T","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"U","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"V","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"W","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"X","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"Y","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"Z","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"/","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"#","",.)
				replace z_street_numeric = subinstr(z_street_numeric,"-","",.)
				replace z_street_numeric = subinstr(z_street_numeric,".","",.)
			gen z_street_alpha = z_street_short
				replace z_street_alpha = subinstr(z_street_alpha,"0","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"1","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"2","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"3","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"4","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"5","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"6","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"7","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"8","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"9","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"/","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"#","",.)
				replace z_street_alpha = subinstr(z_street_alpha,"-","",.)
				replace z_street_alpha = subinstr(z_street_alpha,".","",.)
			
			drop str_dist
			
			count
				local topaddress = r(N)
				*181909233
			
			keep ams_id importparcelid createdatetime z_street_short rx_street_short z_street_alpha rx_street_alpha rx_street_numeric z_street_numeric
			
				compress
			save RFSRX_Match_Working, replace
	
	
		local batches = 16
		forvalues batch = 1(1)`batches' {

			
			local firstaddress=floor((`topaddress'/`batches')*(`batch'-1))+1
			local lastaddress=floor((`topaddress'/`batches')*(`batch'))
			
			
			use in `firstaddress'/`lastaddress' using RFSRX_Match_Working, clear
			
				strdist z_street_short rx_street_short, gen(str_dist)
					drop z_street_short rx_street_short
				strdist z_street_alpha rx_street_alpha, gen(str_dist_alpha)
					drop z_street_alpha rx_street_alpha
				strdist z_street_numeric rx_street_numeric, gen(str_dist_numeric)
					drop rx_street_numeric z_street_numeric
				
				compress
			save RFSRX_Match_Working_`batch', replace
	
		}
		
				clear
			forvalues batch=1/16 {
				append using RFSRX_Match_Working_`batch'
			}
				compress
			save RFSRX_Match, replace

	use ams_id importparcelid createdatetime str_dist str_dist_alpha str_dist_numeric using RFSRX_Match, clear
		
			gen keep = 0
			replace keep = 1 if str_dist==0
			replace keep = 1 if str_dist_alpha<=2 & str_dist_numeric==0 & keep == 0
			
			by ams_id, sort: egen keeptotal=total(keep)
			
			by ams_id, sort: gen counter=_n

		
			keep if keep==1
			
				keep ams_id importparcelid createdatetime
				duplicates drop
			sort importparcelid
				compress
		save RFSRX_STMerge_01, replace
			keep importparcelid
			duplicates drop
		save RFSRX_STMerge_01_UniqueZID, replace
		use RFSRX_STMerge_01, clear
			keep ams_id
			duplicates drop
		save RFSRX_STMerge_01_MergedRedXRecords, replace
	
	use ams_id ams_county ams_state ams_zip num_bed sq_ft longitude latitude using RX_FullListingPlatform_Properties, clear
	
		keep if ams_id!=""
		
		preserve
		
			keep ams_id longitude latitude ams_zip
		
			replace latitude = round(latitude,0.00001)
			replace longitude = round(longitude,0.00001)
			
			replace latitude=abs(latitude)
			replace longitude=-abs(longitude)
			
			replace latitude=. if latitude>90 | latitude<-90
			replace longitude=. if longitude>180 | longitude<-180
			
			drop if latitude==. | longitude==.
			
			duplicates drop
			
			collapse (median) latitude longitude, by(ams_id ams_zip)
			
			replace latitude = round(latitude,0.00001)
			replace longitude = round(longitude,0.00001)
			
			rename latitude lp_lat
			rename longitude lp_lon
			
				compress
			save RFSRX_FullListingPlatform_LatLons, replace
		
		restore
		
		replace ams_state = "" if !(ams_state=="AK" |  ams_state=="AL" |  ams_state=="AR" |  ams_state=="AZ" |  ams_state=="CA" |  ams_state=="CO" |  ams_state=="CT" |  ams_state=="DC" |  ams_state=="DE" |  ams_state=="FL" |  ams_state=="GA" |  ams_state=="HI" |  ams_state=="IA" |  ams_state=="ID" |  ams_state=="IL" |  ams_state=="IN" |  ams_state=="KS" |  ams_state=="KY" |  ams_state=="LA" |  ams_state=="MA" |  ams_state=="MD" |  ams_state=="ME" |  ams_state=="MI" |  ams_state=="MN" |  ams_state=="MO" |  ams_state=="MS" |  ams_state=="MT" |  ams_state=="NC" |  ams_state=="ND" |  ams_state=="NE" |  ams_state=="NH" |  ams_state=="NJ" |  ams_state=="NM" |  ams_state=="NV" |  ams_state=="NY" |  ams_state=="OH" |  ams_state=="OK" |  ams_state=="OR" |  ams_state=="PA" |  ams_state=="RI" |  ams_state=="SC" |  ams_state=="SD" |  ams_state=="TN" |  ams_state=="TX" |  ams_state=="UT" |  ams_state=="VA" |  ams_state=="VT" |  ams_state=="WA" |  ams_state=="WI" |  ams_state=="WV" |  ams_state=="WY")
		
		by ams_id, sort: egen modecounty = mode(ams_county)
		by ams_id, sort: egen modestate = mode(ams_state)
		
		replace ams_county = modecounty if modecounty<.
		replace ams_state = modestate if modestate!=""
		
		drop modecounty modestate
		
		replace ams_county = . if ams_state == ""
		replace ams_state = "" if ams_county == .
		
		by ams_id, sort: egen modezip = mode(ams_zip)
			replace ams_zip = modezip if modezip<.
			drop modezip
			
		duplicates drop
		
		by ams_id, sort: egen counter=total(1)
			drop if counter>1			
			drop counter

		replace sq_ft = . if sq_ft==0
		winsor sq_ft, generate(w_sq_ft) p(0.05)
			drop sq_ft
		gen prop_sqftbuckets = round(w_sq_ft,5)/5
			drop w_sq_ft
			replace prop_sqftbuckets = 0 if prop_sqftbuckets==. & ams_zip<.
		
		
		gen prop_beds=round(num_bed,1)
			drop num_bed
			replace prop_beds=6 if prop_beds>6 & prop_beds<.
			replace prop_beds=0 if prop_beds==. & ams_zip<.
			
		duplicates drop
		
		compress
	save RFSRX_ListingPropertyInfo, replace
	
	use transid importparcelid recordingdate propertyusestndcode using RX_ZTRAX_DatesandCodes, clear
		
		merge m:1 importparcelid using RFSRX_ZTS_ZTRAX_Props
			keep if _merge==3
			drop _merge
		duplicates drop
		sort z_zip

			gen tranyearmonth = year(recordingdate)*12 + month(recordingdate)
			keep if tranyearmonth>24186
			drop propertyusestndcode
			
			by importparcelid tranyearmonth, sort: egen counter=total(1)
				drop if counter>1
				drop counter
			
			sort z_zip
			compress
		save RFSRX_ZTS_ZWAddresses_CleanShort, replace
			gen double address=_n
			collapse (min) firstaddress=address (max) lastaddress=address, by(z_zip)
				rename z_zip zip
			compress
		save RFSRX_ZTS_ZWZipIndex_CleanShort, replace
	
	use lead_id ams_id createdate square_feet bedrooms latitude longitude zip using RX_Leads, clear
		
		preserve
				keep lead_id createdate latitude longitude zip
			
				rename createdate createdatetime
				gen createdate = dofc(createdatetime)
					format %td createdate
					drop createdatetime
				
				rename latitude rx_lat
				rename longitude rx_lon
				rename zip rx_zip
				drop if rx_lat==. | rx_lon==. | rx_zip==.

				sort rx_zip lead_id createdate
				
				compress
			save RFSRX_ZTS_RXAddresses, replace
				keep rx_zip
				rename rx_zip zip
				gen counter=1
				collapse (sum) counter, by(zip)
				compress
			save RFSRX_ZTS_Zips_Init, replace
				merge 1:1 zip using RFSRX_PCS_ZWZipIndex
					keep if _merge==3
					drop _merge
				set seed 19851985
				gen rnum=runiform()
				sort rnum
				drop rnum
				compress
			save RFSRX_PCS_Zips, replace
			
			use RFSRX_ZTS_Zips_Init, clear
				merge 1:1 zip using RFSRX_ZTS_ZWZipIndex_CleanShort
					keep if _merge==3
					drop _merge
				set seed 19851985
				gen rnum=runiform()
				sort rnum
				drop rnum
				compress
			save RFSRX_ZTS_Zips_CleanShort, replace
			
			use ams_id list_date using RX_FullListingPlatform_Listings, clear

				duplicates drop
				
				drop if list_date==.
				
				merge m:1 ams_id using RFSRX_FullListingPlatform_LatLons
					drop if _merge==2
					drop _merge
					
				rename ams_zip lp_zip
				
				sort lp_zip
				compress
			save RFSRX_ListingPlatformSearch_ListingPlatform_Addresses, replace

			use RFSRX_ListingPlatformSearch_ListingPlatform_Addresses, clear
				gen double address=_n
				collapse (min) firstaddress=address (max) lastaddress=address, by(lp_zip)
					rename lp_zip zip
				compress
			save RFSRX_ListingPlatformSearch_ListingPlatformZipIndex, replace
			
			use RFSRX_ZTS_Zips_Init, clear
				merge 1:1 zip using RFSRX_ListingPlatformSearch_ListingPlatformZipIndex
					keep if _merge==3
					drop _merge
				set seed 19851985
				gen rnum=runiform()
				sort rnum
				drop rnum
				compress
			save RFSRX_ListingPlatformSearch_Zips, replace
			
		restore
		
		preserve
			
			keep lead_id ams_id zip
				duplicates drop
			save RFSRX_leadams_lookup, replace
			use RFSRX_STMerge_01, clear
				keep ams_id importparcelid
				joinby ams_id using RFSRX_leadams_lookup
				keep lead_id importparcelid zip
				duplicates drop
				sort zip importparcelid lead_id
				compress
			save RFSRX_AddressMatchResults_wZip, replace
				drop zip
				duplicates drop
				sort importparcelid lead_id
				compress
			save RFSRX_AddressMatchResults, replace
			use RFSRX_AddressMatchResults_wZip, clear
				merge m:1 zip using RFSRX_ZTS_Zips_CleanShort
				keep if _merge==3
				drop counter firstaddress lastaddress _merge
				sort zip importparcelid lead_id
				gen byte zillowmatched = 1
				compress
			save RFSRX_AddressMatchResults_wZip_Short, replace
			
		restore
		
		preserve
		
			keep lead_id square_feet bedrooms latitude longitude zip
			
				rename latitude rx_lat
				rename longitude rx_lon
	
				drop if rx_lat==. | rx_lon==. | zip==.

				drop zip
				
					replace square_feet = strlower(square_feet)
					replace square_feet = subinstr(square_feet," ","",.)
					
					replace square_feet = subinstr(square_feet,"sq.ft.","",.)
					replace square_feet = subinstr(square_feet,"sq.ft","",.)
					replace square_feet = subinstr(square_feet,"sqft","",.)
					replace square_feet = subinstr(square_feet,"sqf","",.)
					replace square_feet = subinstr(square_feet,"sf","",.)
					replace square_feet = subinstr(square_feet,"sq","",.)
					
					destring square_feet, replace force
					
					
					replace square_feet = . if square_feet==0
					winsor square_feet, gen(w_square_feet) p(.01)
						drop square_feet
				
					replace bedrooms = subinstr(bedrooms,"BED","",.)
					replace bedrooms = subinstr(bedrooms,",","",.)
					replace bedrooms = subinstr(bedrooms,"½",".5",.)
					replace bedrooms = subinstr(bedrooms,"Â","",.)
					replace bedrooms = subinstr(bedrooms,"MUST","",.)
					replace bedrooms = subinstr(bedrooms," ","",.)
					
					destring bedrooms, replace
				
					
					
						replace bedrooms = . if bedrooms<1
						replace bedrooms = . if bedrooms>10
					replace bedrooms = 6 if bedrooms > 6 & bedrooms<.


					rename bedrooms rx_beds
					rename w_square_feet rx_sqft
				
		 		compress
		 	save RFSRX_ListPropCharSearch_RXAddresses, replace
				keep lead_id rx_sqft rx_beds
				compress
			save RFSRX_LeadPropChars, replace
			use RFSRX_ListPropCharSearch_RXAddresses, replace
				keep lead_id rx_lat rx_lon
				compress
			save RFSRX_LeadLocs, replace
				
		
		restore
		
		preserve
			
			keep lead_id ams_id
			rename ams_id matched_ams_id
			duplicates drop
			sort lead_id
				compress
			save RFSRX_leadsamsmatches, replace
			
		restore
		
		drop square_feet bedrooms latitude longitude zip
	
			rename createdate createdatetime
		
		joinby ams_id createdatetime using RFSRX_STMerge_01
		
		keep lead_id importparcelid
		
		duplicates drop
		
		compress
	save RFSRX_Leads_Importparcelids, replace
	
	local batches = 16
	forvalues batch = 1(1)`batches' {
	
	frame change default
	
	clear all
	
	frame create RXAddresses2

	frame create RXAddresses
	frame change RXAddresses
	
	use RFSRX_ZTS_RXAddresses, clear
	
	frame create LPSearchResults
	
	
	frame create Zips
	frame change Zips
	
	use RFSRX_ListingPlatformSearch_Zips, clear
		
		local N = _N
		
		local last = floor(min(`batch'*`N'/`batches',`N'))
		local first = floor(min(`batch'*`N'/`batches'+1-`N'/`batches',`N'))
		
		if `first'==`last' & `last'==`N'{
			disp "You did too many batches!!"
			disp "if there are exactly 1000*n+1 zips then you need to do the last row manually"
			crashmenow
		}
		
		forvalues i = `first'/`last' {
			frame change Zips
			
			local zip = zip[`i']
			local firstaddress = firstaddress[`i']
			local lastaddress = lastaddress[`i']
			
			disp `zip'
			disp "Doing zip number `i' for batch `batch' going from `first' to `last' out of total `N'"
			disp "From `firstaddress' to `lastaddress'"
			display c(current_time)
			
			frame drop RXAddresses2 
			frame copy RXAddresses RXAddresses2
			frame change RXAddresses2
			
				keep if rx_zip==`zip'
					drop rx_zip
					gen matchpoint = 1
					compress
				save RFSRX_tempziptrans_`batch', replace
			
			frame change default
				
				use in `firstaddress'/`lastaddress' using RFSRX_ListingPlatformSearch_ListingPlatform_Addresses, clear
					drop lp_zip
					gen matchpoint = 1
					compress
					
				joinby matchpoint using RFSRX_tempziptrans_`batch'
				drop matchpoint
		
				if _N>0{
					
					timer on 1
					gen date_dist = list_date - createdate
					timer off 1
					timer list
					timer clear
					
					keep if date_dist<=365 & date_dist>=-90
					
					if _N>0{
					
						timer on 1
						geodist lp_lat lp_lon rx_lat rx_lon, gen(geo_dist) miles sphere
						timer off 1
						timer list
						timer clear

						keep if geo_dist<=2
					} 
					else {
							gen geo_dist = .
					}

					keep ams_id lead_id geo_dist date_dist list_date
						order ams_id lead_id geo_dist date_dist list_date
						
						save temp_LPSearchResults_`batch', replace
						
				if _N>0{
					frame change LPSearchResults
						append using temp_LPSearchResults_`batch'
						if mod(`i',100)==0 {
							save RFSRX_ListingPlatformSearch_Results_`batch', replace
						}
					}
				}
		}
		
			frame change LPSearchResults
		save RFSRX_ListingPlatformSearch_Results_`batch', replace
			frame change default
			frame drop RXAddresses 
			frame drop RXAddresses2 
			frame drop LPSearchResults 
			frame drop Zips

		use RFSRX_ListingPlatformSearch_Results_`batch', clear
		
			merge m:1 lead_id using RFSRX_leadsamsmatches
				drop if _merge==2
				gen identicalmatch = 0
					replace identicalmatch = 1 if ams_id==matched_ams_id
				drop _merge matched_ams_id
				
				replace geo_dist = 0 if identicalmatch==1
				
				gen byte listcount_365_025 = 0
					replace listcount_365_025 = 1 if date_dist<=365 & date_dist>=0 & geo_dist*100<=25
					
				preserve
							
					keep if listcount_365_025==1
					keep ams_id list_date lead_id
					
					keep if list_date>=20454 & list_date<=21396
					
						compress
					save RFSRX_ProximateLPListings_`batch', replace
				
				restore
				
				drop listcount_365_025
				
				foreach distlimit in 025 200 {
				
					foreach daylimit in 365 270 180 150 120 90 60 30 {

						gen byte listcount_other_`daylimit'_`distlimit' = 0
							replace listcount_other_`daylimit'_`distlimit' = 1 if date_dist<=`daylimit' & date_dist>=0 & geo_dist*100<=`distlimit' & identicalmatch==0
							
						}
					
				}
				
				foreach negdaylimit in 90 {

					gen byte listcount_other_m`negdaylimit'_`distlimit' = 0
						replace listcount_other_m`negdaylimit'_`distlimit' = 1 if date_dist>=-`negdaylimit' & date_dist<0 & geo_dist*100<=`distlimit' & identicalmatch==0
					

					
				}

			
			
			gen byte listcount_m90_025 = 0
				replace listcount_m90_025 = 1 if date_dist>=-90 & date_dist<0 & geo_dist*100<=25
			
			keep lead_id listcount_* listcount_other_*
			
			sort lead_id

			collapse (sum) listcount_*, by(lead_id)
			
				
				compress		
			save RFSRX_ListingPlatformSearch_Results_Collapsed_`batch', replace

			
	}
		
		
		clear
	forvalues batch = 1/16 {
	    append using RFSRX_ListingPlatformSearch_Results_Collapsed_`batch'
	}
	
		compress
	save RFSRX_ListingPlatformSearch_Results, replace
		
			clear
	forvalues batch = 1/16 {
		
		append using RFSRX_ProximateLPListings_`batch'
		
	}
	
		compress
	save RFSRX_ProximateLPListings, replace
	
	local batches = 16
	forvalues batch = 1(1)`batches' {

		frame change default
		
		clear all
		
		frame create zillowmatched2
		
		frame create zillowmatched
		frame change zillowmatched
		
		use RFSRX_AddressMatchResults_wZip_Short, clear
		
		frame create RXAddresses2

		frame create RXAddresses
		frame change RXAddresses
		
		use RFSRX_ZTS_RXAddresses, clear
		
		frame create results
		
		frame create Zips
		frame change Zips
		
		use RFSRX_ZTS_Zips_CleanShort, clear
			
			local N = _N
			
			local last = floor(min(`batch'*`N'/`batches',`N'))
			local first = floor(min(`batch'*`N'/`batches'+1-`N'/`batches',`N'))
			
			if `first'==`last' & `last'==`N'{
				disp "You did too many batches!!"
				disp "if there are exactly 1000*n+1 zips then you need to do the last row manually"
				crashmenow
			}
			
			forvalues i = `first'/`last' {
				frame change Zips
				
				local zip = zip[`i']
				local firstaddress = firstaddress[`i']
				local lastaddress = lastaddress[`i']
				
				disp `zip'
				disp "Doing zip number `i' for batch `batch' going from `first' to `last' out of total `N'"
				disp "From `firstaddress' to `lastaddress'"
				display c(current_time)
				
				frame drop RXAddresses2 
				frame copy RXAddresses RXAddresses2
				frame change RXAddresses2
				
					keep if rx_zip==`zip'
						drop rx_zip
						gen matchpoint = 1
						compress
					save RFSRX_tempziptrans_`batch', replace
					
				capture frame drop zillowmatched2
				frame copy zillowmatched zillowmatched2
				frame change zillowmatched2
					keep if zip==`zip'
					drop zip
					save RFSRX_tempzillowmatched_`batch', replace
					
				
				frame change default
				
					use in `firstaddress'/`lastaddress' using RFSRX_ZTS_ZWAddresses_CleanShort, clear
						drop z_zip
						gen matchpoint = 1
						compress
						
					joinby matchpoint using RFSRX_tempziptrans_`batch'
					drop matchpoint
			
					if _N>0{
						
						timer on 2
						gen date_dist = recordingdate - createdate
						timer off 2
						timer list
						timer clear
						
						keep if date_dist<=365 & date_dist>=-90
						
						merge m:1 importparcelid lead_id using RFSRX_tempzillowmatched_`batch'
							drop if _merge==2
							drop _merge
						
						if _N>0{
							timer on 1
							geodist z_lat z_lon rx_lat rx_lon, gen(geo_dist) miles sphere
							timer off 1
							timer list
							timer clear
							
							replace geo_dist=0 if zillowmatched==1
							drop zillowmatched
							
							keep if geo_dist<=2
						}
						
						else {
							gen geo_dist = .
						}
						
						

						keep transid importparcelid lead_id geo_dist date_dist
							order transid importparcelid lead_id geo_dist date_dist
						

					
					if _N>0{
						
						save temp_ZTS_Results_`batch', replace
						frame change results
						append using temp_ZTS_Results_`batch'
							compress
						frame change default

						}
					}
		
			}
					
					
					frame drop zillowmatched
					frame drop zillowmatched2
					frame drop RXAddresses
					frame drop RXAddresses2
					frame drop Zips
					
					frame change results

						
						merge m:1 importparcelid lead_id using RFSRX_AddressMatchResults
							drop if _merge==2
							gen oth_cl = 1 if _merge==1
							drop _merge
						
						local loopcount = 1

						foreach daylimit in 365 270 180 150 120 90 60 30 {
							
							foreach distlimit in 200 025 {
								
								disp "batch `batch', loop `loopcount' of 18"
								
								gen byte trancount_oth_cl_`daylimit'_`distlimit' = 0
									replace trancount_oth_cl_`daylimit'_`distlimit' = 1 if date_dist<=`daylimit' & date_dist>=0 & geo_dist*100<=`distlimit' & oth_cl==1
								
								local loopcount = `loopcount' + 1
								
							}
						}
						
						foreach negdaylimit in 90 {
							
							foreach distlimit in 200 025 {
								
								disp "batch `batch', loop `loopcount' of 18"
								
								gen byte trancount_m`negdaylimit'_`distlimit' = 0
									replace trancount_m`negdaylimit'_`distlimit' = 1 if date_dist>=-`negdaylimit' & date_dist<0 & geo_dist*100<=`distlimit'
								
								gen byte trancount_oth_cl_m`negdaylimit'_`distlimit' = 0
									replace trancount_oth_cl_m`negdaylimit'_`distlimit' = 1 if date_dist>=-`negdaylimit' & date_dist<0 & geo_dist*100<=`distlimit' & oth_cl==1
								
								local loopcount = `loopcount' + 1
								
							}
						}
						
							compress
						save RFSRX_HedTrans_Results_UnCollapsed_`batch', replace

					frame change default
					frame drop results

		}

	frame create results
		forvalues batch = 1/16 {
			
			use RFSRX_HedTrans_Results_UnCollapsed_`batch', replace
			
			collapse (sum) trancount_*, by(lead_id)
			
				compress
			save temp_deleteme, replace
			
			frame change results
				append using temp_deleteme
			frame change default
		}
	frame change results
		save RFSRX_ZTS_Results, replace
	frame change default
	frame drop results
	
	
	use ams_id longitude latitude ams_zip ams_street using RX_FullListingPlatform_Properties, clear
		
		replace latitude = round(latitude,0.00001)
		replace longitude = round(longitude,0.00001)
		
		replace latitude=abs(latitude)
		replace longitude=-abs(longitude)
		
		replace latitude=. if latitude>90 | latitude<-90
		replace longitude=. if longitude>180 | longitude<-180

		replace latitude = . if latitude>90
		replace longitude = . if longitude>180 | longitude<-180
		
		duplicates drop
		
		drop if ams_zip==.
		
		by ams_id ams_zip, sort: egen medlat=median(latitude)
		by ams_id ams_zip, sort: egen medlon=median(longitude)
		
		drop latitude longitude
		
		rename medlat lp_lat
		rename medlon lp_lon
		
		duplicates drop
		
		replace lp_lat = round(lp_lat,0.00001)
		replace lp_lon = round(lp_lon,0.00001)
		
		rename ams_street lp_street
		
		replace lp_street = strupper(lp_street)
		gen lp_street_short = lp_street
		
		replace lp_street_short = subinstr(lp_street_short," PT","",.)
		replace lp_street_short = subinstr(lp_street_short," DR","",.)
		replace lp_street_short = subinstr(lp_street_short," ST","",.)
		replace lp_street_short = subinstr(lp_street_short," AVE","",.)
		replace lp_street_short = subinstr(lp_street_short," RD","",.)
		replace lp_street_short = subinstr(lp_street_short," CT","",.)
		replace lp_street_short = subinstr(lp_street_short," TRCE","",.)
		
		replace lp_street_short = subinstr(lp_street_short," POINT","",.)
		replace lp_street_short = subinstr(lp_street_short," DRIVE","",.)
		replace lp_street_short = subinstr(lp_street_short," STREET","",.)
		replace lp_street_short = subinstr(lp_street_short," AVENUE","",.)
		replace lp_street_short = subinstr(lp_street_short," ROAD","",.)
		replace lp_street_short = subinstr(lp_street_short," COURT","",.)
		replace lp_street_short = subinstr(lp_street_short," TERRACE","",.)
		
		replace lp_street_short = subinstr(lp_street_short," ","",.)
		
		gen lp_street_numeric = lp_street_short
			replace lp_street_numeric = subinstr(lp_street_numeric,"A","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"B","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"C","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"D","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"E","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"F","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"G","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"H","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"I","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"J","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"K","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"L","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"M","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"N","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"O","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"P","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"Q","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"R","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"S","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"T","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"U","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"V","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"W","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"X","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"Y","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"Z","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"/","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"#","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"-","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,".","",.)
		gen lp_street_alpha = lp_street_short
			replace lp_street_alpha = subinstr(lp_street_alpha,"0","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"1","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"2","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"3","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"4","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"5","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"6","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"7","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"8","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"9","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"/","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"#","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"-","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,".","",.)
		
		duplicates drop
		
		rename ams_zip lp_zip
		
		sort ams_id
		
		gen double ams_id_short=_n
			order ams_id_short, after(ams_id)
		
		drop lp_street
		
		compress
		
		preserve
			
			keep ams_id ams_id_short
				compress
			save RFSRX_ZLPMatch_LPProperties_amslookup, replace
			
		restore

		drop ams_id lp_street_numeric lp_street_alpha
			
			compress
		save RFSRX_ZLPMatch_LPProperties, replace

	use RFSRX_Addresses_Z_Short, clear
	
		replace z_lat = round(z_lat,0.00001)
		replace z_lon = round(z_lon,0.00001)
		
		replace z_lat=abs(z_lat)
		replace z_lon=-abs(z_lon)
		
		replace z_lat=. if z_lat>90 | z_lat<-90
		replace z_lon=. if z_lon>180 | z_lon<-180

		replace z_lat = . if z_lat>90
		replace z_lon = . if z_lon>180 | z_lon<-180
		
		duplicates drop
		
		drop if z_zip==.
		
		by importparcelid z_zip, sort: egen medlat=median(z_lat)
		by importparcelid z_zip, sort: egen medlon=median(z_lon)
		
		drop z_lat z_lon
		
		rename medlat z_lat
		rename medlon z_lon
		
		duplicates drop
		
		replace z_lat = round(z_lat,0.00001)
		replace z_lon = round(z_lon,0.00001)
		
		replace z_street_short = subinstr(z_street_short," PT","",.)
		replace z_street_short = subinstr(z_street_short," DR","",.)
		replace z_street_short = subinstr(z_street_short," ST","",.)
		replace z_street_short = subinstr(z_street_short," AVE","",.)
		replace z_street_short = subinstr(z_street_short," RD","",.)
		replace z_street_short = subinstr(z_street_short," CT","",.)
		replace z_street_short = subinstr(z_street_short," TRCE","",.)
		
		replace z_street_short = subinstr(z_street_short," POINT","",.)
		replace z_street_short = subinstr(z_street_short," DRIVE","",.)
		replace z_street_short = subinstr(z_street_short," STREET","",.)
		replace z_street_short = subinstr(z_street_short," AVENUE","",.)
		replace z_street_short = subinstr(z_street_short," ROAD","",.)
		replace z_street_short = subinstr(z_street_short," COURT","",.)
		replace z_street_short = subinstr(z_street_short," TERRACE","",.)
		
		replace z_street_short = subinstr(z_street_short," ","",.)
		
		gen z_street_numeric = z_street_short
			replace z_street_numeric = subinstr(z_street_numeric,"A","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"B","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"C","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"D","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"E","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"F","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"G","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"H","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"I","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"J","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"K","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"L","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"M","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"N","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"O","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"P","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"Q","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"R","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"S","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"T","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"U","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"V","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"W","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"X","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"Y","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"Z","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"/","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"#","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"-","",.)
			replace z_street_numeric = subinstr(z_street_numeric,".","",.)
		gen z_street_alpha = z_street_short
			replace z_street_alpha = subinstr(z_street_alpha,"0","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"1","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"2","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"3","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"4","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"5","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"6","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"7","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"8","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"9","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"/","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"#","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"-","",.)
			replace z_street_alpha = subinstr(z_street_alpha,".","",.)
		
		duplicates drop
		
			sort z_zip
			drop z_street_numeric z_street_alpha
			compress
		save RFSRX_ZLPMatch_ZAddresses_Short, replace
		
		use RFSRX_ZLPMatch_ZAddresses_Short, clear
			gen double address=_n
			collapse (min) firstaddress=address (max) lastaddress=address, by(z_zip)
				rename z_zip zip
			compress
		save RFSRX_ZLPMatch_ZZipIndex, replace
		
		use RFSRX_ZLPMatch_LPProperties, clear
			keep lp_zip
			rename lp_zip zip
			gen counter=1
			collapse (sum) counter, by(zip)
			
			merge 1:1 zip using RFSRX_ZLPMatch_ZZipIndex
				keep if _merge==3
				drop _merge
			set seed 19851985
			gen rnum=runiform()
			sort rnum
			drop rnum
			compress
		save RFSRX_ZLPMatch_Zips, replace
	

		forvalues batch = 1(1)16 {
	
		frame change default
		
		clear all
		
		frame create LPAddresses2

		frame create LPAddresses
		frame change LPAddresses
		
		use RFSRX_ZLPMatch_LPProperties, clear
		
		frame create MatchResults
		frame change MatchResults

		
		frame create Zips
		frame change Zips
		
		use RX_ZLPMatch_Zips, clear
			
			local N = _N
			
			local last = min(`batch'*2000,`N')
			local first = min((`batch'*2000)-1999,`N')
			
			if `first'==`last' & `last'==`N'{
				disp "You did too many batches!!"
				disp "if there are exactly 1000*n+1 zips then you need to do the last row manually"
				crashmenow
			}
			
			forvalues i = `first'/`last' {
				frame change Zips
				
				local zip = zip[`i']
				local firstaddress = firstaddress[`i']
				local lastaddress = lastaddress[`i']
				
				disp `zip'
				disp "Doing zip number `i' for batch `batch' going from `first' to `last' out of total `N'"
				disp "From `firstaddress' to `lastaddress'"
				display c(current_time)

				frame drop LPAddresses2 
				frame copy LPAddresses LPAddresses2
				frame change LPAddresses2
				
					keep if lp_zip==`zip'
						drop lp_zip
						gen matchpoint = 1
						compress
					save RFSRX_tempziptrans_`batch', replace
				
				frame change default

					use in `firstaddress'/`lastaddress' using RFSRX_ZLPMatch_ZAddresses_Short, clear
						drop z_zip
						gen matchpoint = 1
						compress
						
					joinby matchpoint using RFSRX_tempziptrans_`batch'
					drop matchpoint
			
					if _N>0{
						
						count if (z_lat<. & z_lon<. & lp_lat<. & lp_lon<.)
						
						if r(N)>0{
							timer on 1
							geodist z_lat z_lon lp_lat lp_lon, gen(geo_dist) sphere miles
							timer off 1
							timer list
							timer clear
						}
						else {
							gen geo_dist=.
						}
						
						timer on 2
						strdist z_street_short lp_street_short, gen(str_dist_short) maxdist(10)
						timer off 2
						timer list
						timer clear

						keep ams_id_short importparcelid geo_dist str_dist_short
							order ams_id_short importparcelid geo_dist str_dist_short
						
						timer on 3
						sort ams_id_short
						timer off 3
						timer list
						timer clear
						
						timer on 4
						by ams_id_short, sort: egen topgeodist=rank(geo_dist), track
						by ams_id_short, sort: egen topstrdist=rank(str_dist_short), track
						timer off 4
						timer list
						timer clear

						
						keep if str_dist<5 | topstrdist<=10 | topgeodist<=10 | geo_dist<=.01
						
						save temp_results_`batch', replace
					
					if _N>0{
					
						frame change MatchResults
							
							append using temp_results_`batch'
							if mod(`i',10)==0 {
								
								save RFSRX_ZLPMatch_Results_`batch', replace
								
							}
						}
					}
			}
			
			frame change MatchResults
			save RFSRX_ZLPMatch_Results_`batch', replace
		
		
		
	}
		
	
		clear
	forvalues batch = 1/16 {
		
		append using RFSRX_ZLPMatch_Results_`batch'
	
	}

		merge m:1 ams_id_short using RFSRX_ZLPMatch_LPProperties
			drop if _merge==2
			drop _merge
			
		merge m:1 importparcelid using RFSRX_ZLPMatch_ZAddresses_Short
			drop if _merge==2
			drop _merge
		
		keep ams_id_short importparcelid str_dist_short lp_street_short z_street_short
		
		gen byte keep = 0
			replace keep = 1 if str_dist_short==0
			drop str_dist_short
		
		gen z_street_alpha = z_street_short
			replace z_street_alpha = subinstr(z_street_alpha,"0","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"1","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"2","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"3","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"4","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"5","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"6","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"7","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"8","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"9","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"/","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"#","",.)
			replace z_street_alpha = subinstr(z_street_alpha,"-","",.)
			replace z_street_alpha = subinstr(z_street_alpha,".","",.)
			
		
		gen lp_street_alpha = lp_street_short
			replace lp_street_alpha = subinstr(lp_street_alpha,"0","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"1","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"2","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"3","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"4","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"5","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"6","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"7","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"8","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"9","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"/","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"#","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,"-","",.)
			replace lp_street_alpha = subinstr(lp_street_alpha,".","",.)
				
		strdist z_street_alpha lp_street_alpha, gen(str_dist_alpha)
			drop z_street_alpha lp_street_alpha
			
		gen byte keep_alpha = 0
			replace keep_alpha = 1 if str_dist_alpha<=2
			drop str_dist_alpha
			
		keep if keep==1 | keep_alpha==1
			drop keep_alpha
		
		gen z_street_numeric = z_street_short
		drop z_street_short
			replace z_street_numeric = subinstr(z_street_numeric,"A","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"B","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"C","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"D","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"E","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"F","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"G","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"H","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"I","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"J","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"K","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"L","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"M","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"N","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"O","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"P","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"Q","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"R","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"S","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"T","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"U","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"V","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"W","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"X","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"Y","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"Z","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"/","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"#","",.)
			replace z_street_numeric = subinstr(z_street_numeric,"-","",.)
			replace z_street_numeric = subinstr(z_street_numeric,".","",.)
		
		gen lp_street_numeric = lp_street_short
		drop lp_street_short
			replace lp_street_numeric = subinstr(lp_street_numeric,"A","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"B","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"C","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"D","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"E","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"F","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"G","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"H","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"I","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"J","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"K","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"L","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"M","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"N","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"O","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"P","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"Q","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"R","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"S","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"T","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"U","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"V","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"W","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"X","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"Y","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"Z","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"/","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"#","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,"-","",.)
			replace lp_street_numeric = subinstr(lp_street_numeric,".","",.)
			
		strdist z_street_numeric lp_street_numeric, gen(str_dist_numeric)
			drop z_street_numeric lp_street_numeric

		keep if keep==1 | str_dist_numeric==0
			drop keep str_dist_numeric

		
		merge m:1 ams_id_short using RFSRX_ZLPMatch_LPProperties_amslookup
			drop if _merge==2
			drop _merge
			
		order ams_id, after(ams_id_short)
		drop ams_id_short
		
		sort ams_id importparcelid
		
			compress
		save RFSRX_ZLPMatch_Results, replace

	use RFSRX_ZLPMatch_Results, clear
		keep importparcelid
		duplicates drop
		gen byte brokeredtransaction = 1
		compress
	save RFSRX_BrokeredZTRAXProperties, replace
	
	frame create results
		forvalues batch = 1/16 {
			
			use lead_id importparcelid trancount_oth_cl_m90_025 using RFSRX_HedTrans_Results_UnCollapsed_`batch', replace
			
			merge m:1 importparcelid using RFSRX_BrokeredZTRAXProperties
				keep if _merge==3
				drop _merge
				
			drop importparcelid brokeredtransaction
			
			rename trancount_oth_cl_m90_025 brok_trancount_oth_cl_m90_025

			collapse (sum) brok_trancount_oth_cl_m90_025, by(lead_id)
			
				compress
			save temp_deleteme, replace
			
			frame change results
				append using temp_deleteme
			frame change default
		}
	frame change results
		save RFSRX_BrokeredTransactions, replace
	frame change default
	frame drop results

	frame create results
		forvalues batch = 1/16 {
			
			use transid lead_id trancount_oth_cl_365_025 using RFSRX_HedTrans_Results_UnCollapsed_`batch', clear
			
			keep if trancount_oth_cl_365_025==1
			
			drop trancount_oth_cl_365_025
			
				compress
			save temp_deleteme, replace
			
			frame change results
				append using temp_deleteme
			frame change default
		
		}
	frame change results
		save RFSRX_ProximateTransactions, replace
	frame change default
	frame drop results
	
		
		use RFSRX_Addresses_RX_Short, clear
			
			replace rx_street_short = subinstr(rx_street_short,"PT","",.)
			replace rx_street_short = subinstr(rx_street_short,"DR","",.)
			replace rx_street_short = subinstr(rx_street_short,"ST","",.)
			replace rx_street_short = subinstr(rx_street_short,"AVE","",.)
			replace rx_street_short = subinstr(rx_street_short,"RD","",.)
			replace rx_street_short = subinstr(rx_street_short,"CT","",.)
			replace rx_street_short = subinstr(rx_street_short,"TRCE","",.)
			replace rx_street_short = subinstr(rx_street_short,"LN","",.)
			
			replace rx_street_short = subinstr(rx_street_short,"POINT","",.)
			replace rx_street_short = subinstr(rx_street_short,"DRIVE","",.)
			replace rx_street_short = subinstr(rx_street_short,"STREET","",.)
			replace rx_street_short = subinstr(rx_street_short,"AVENUE","",.)
			replace rx_street_short = subinstr(rx_street_short,"ROAD","",.)
			replace rx_street_short = subinstr(rx_street_short,"COURT","",.)
			replace rx_street_short = subinstr(rx_street_short,"TERRACE","",.)
			replace rx_street_short = subinstr(rx_street_short,"LANE","",.)

				gen rx_street_numeric = rx_street_short
					replace rx_street_numeric = subinstr(rx_street_numeric,"A","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"B","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"C","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"D","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"E","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"F","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"G","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"H","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"I","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"J","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"K","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"L","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"M","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"N","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"O","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"P","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"Q","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"R","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"S","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"T","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"U","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"V","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"W","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"X","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"Y","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"Z","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"/","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"#","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,"-","",.)
					replace rx_street_numeric = subinstr(rx_street_numeric,".","",.)
				gen rx_street_alpha = rx_street_short
					replace rx_street_alpha = subinstr(rx_street_alpha,"0","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"1","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"2","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"3","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"4","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"5","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"6","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"7","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"8","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"9","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"/","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"#","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,"-","",.)
					replace rx_street_alpha = subinstr(rx_street_alpha,".","",.)
					
			compress
		save RFSRX_Addresses_RX_AlphaNum, replace
			
		
		use ams_id longitude latitude ams_zip ams_street using RX_FullListingPlatform_Properties, clear
		
			replace latitude = round(latitude,0.00001)
			replace longitude = round(longitude,0.00001)
			
			replace latitude=abs(latitude)
			replace longitude=-abs(longitude)
			
			replace latitude=. if latitude>90 | latitude<-90
			replace longitude=. if longitude>180 | longitude<-180
			
			drop if ams_zip==.
			
			replace ams_street = subinstr(ams_street," ","",.)
			replace ams_street = strupper(ams_street)
				compress ams_street
			
			drop if ams_street==""
			
			gen firstcharnumeric = substr(ams_street,1,1)
			destring firstcharnumeric, replace force
			drop if firstcharnumeric==. | firstcharnumeric==0
			drop firstcharnumeric

			rename ams_street ams_street_short
			
			replace ams_street_short = subinstr(ams_street_short," PT","",.)
			replace ams_street_short = subinstr(ams_street_short," DR","",.)
			replace ams_street_short = subinstr(ams_street_short," ST","",.)
			replace ams_street_short = subinstr(ams_street_short," AVE","",.)
			replace ams_street_short = subinstr(ams_street_short," RD","",.)
			replace ams_street_short = subinstr(ams_street_short," CT","",.)
			replace ams_street_short = subinstr(ams_street_short," TRCE","",.)
			
			replace ams_street_short = subinstr(ams_street_short," POINT","",.)
			replace ams_street_short = subinstr(ams_street_short," DRIVE","",.)
			replace ams_street_short = subinstr(ams_street_short," STREET","",.)
			replace ams_street_short = subinstr(ams_street_short," AVENUE","",.)
			replace ams_street_short = subinstr(ams_street_short," ROAD","",.)
			replace ams_street_short = subinstr(ams_street_short," COURT","",.)
			replace ams_street_short = subinstr(ams_street_short," TERRACE","",.)
			
			replace ams_street_short = subinstr(ams_street_short,"PT","",.)
			replace ams_street_short = subinstr(ams_street_short,"DR","",.)
			replace ams_street_short = subinstr(ams_street_short,"ST","",.)
			replace ams_street_short = subinstr(ams_street_short,"AVE","",.)
			replace ams_street_short = subinstr(ams_street_short,"RD","",.)
			replace ams_street_short = subinstr(ams_street_short,"CT","",.)
			replace ams_street_short = subinstr(ams_street_short,"TRCE","",.)
			replace ams_street_short = subinstr(ams_street_short,"LN","",.)
			
			replace ams_street_short = subinstr(ams_street_short,"POINT","",.)
			replace ams_street_short = subinstr(ams_street_short,"DRIVE","",.)
			replace ams_street_short = subinstr(ams_street_short,"STREET","",.)
			replace ams_street_short = subinstr(ams_street_short,"AVENUE","",.)
			replace ams_street_short = subinstr(ams_street_short,"ROAD","",.)
			replace ams_street_short = subinstr(ams_street_short,"COURT","",.)
			replace ams_street_short = subinstr(ams_street_short,"TERRACE","",.)
			replace ams_street_short = subinstr(ams_street_short,"LANE","",.)
			
			gen ams_street_numeric = ams_street_short
					replace ams_street_numeric = subinstr(ams_street_numeric,"A","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"B","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"C","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"D","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"E","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"F","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"G","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"H","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"I","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"J","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"K","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"L","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"M","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"N","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"O","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"P","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"Q","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"R","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"S","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"T","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"U","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"V","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"W","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"X","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"Y","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"Z","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"/","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"#","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,"-","",.)
					replace ams_street_numeric = subinstr(ams_street_numeric,".","",.)
				gen ams_street_alpha = ams_street_short
					replace ams_street_alpha = subinstr(ams_street_alpha,"0","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"1","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"2","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"3","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"4","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"5","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"6","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"7","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"8","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"9","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"/","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"#","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,"-","",.)
					replace ams_street_alpha = subinstr(ams_street_alpha,".","",.)
			
			

			duplicates drop
			
			collapse (median) latitude longitude, by(ams_id ams_zip ams_street_short ams_street_numeric ams_street_alpha)
			
			replace latitude = round(latitude,0.00001)
			replace longitude = round(longitude,0.00001)
			
			rename latitude ams_lat
			rename longitude ams_lon
			
			sort ams_zip
			
			compress
		save RFSRX_FullListingPlatform_Properties_Short_wStrings, replace
			gen double address=_n
			collapse (min) firstaddress=address (max) lastaddress=address, by(ams_zip)
				rename ams_zip zip
			compress
		save RFSRX_LPZipAddresses, replace
			
		use RFSRX_Addresses_RX_Short, clear
			keep rx_zip
			rename rx_zip zip
			gen counter=1
			collapse (sum) counter, by(zip)
			merge 1:1 zip using RFSRX_LPZipAddresses
				keep if _merge==3
				drop _merge
			set seed 19851985
			gen rnum=runiform()
			sort rnum
			drop rnum
			compress
		save RFSRX_LPMatch_Zips, replace

	
	forvalues batch = 1(1)16 {

		frame change default
		
		clear all
		
		frame create RXListings2

		frame create RXListings
		frame change RXListings
		
		use RFSRX_Addresses_RX_AlphaNum, clear
		
		frame create MatchResults
		frame change MatchResults
		

		frame create Zips
		frame change Zips
		
		use RFSRX_LPMatch_Zips, clear

			local N = _N
			
			local last = floor(min(`batch'*`N'/`batches',`N'))
			local first = floor(min(`batch'*`N'/`batches'+1-`N'/`batches',`N'))

			if `first'==`last' & `last'==`N'{
				disp "You did too many batches!!"
				disp "if there are exactly 1000*n+1 zips then you need to do the last row manually"
				crashmenow
			}
			
			forvalues i = `first'/`last' {
				frame change Zips
				
				local zip = zip[`i']
				local firstaddress = firstaddress[`i']
				local lastaddress = lastaddress[`i']
				
				disp `zip'
				disp "Doing zip number `i' for batch `batch' going from `first' to `last' out of total `N'"
				disp "From `firstaddress' to `lastaddress'"
				display c(current_time)
			
				frame drop RXListings2 
				frame copy RXListings RXListings2
				frame change RXListings2
				
					keep if rx_zip==`zip'
						drop rx_zip rx_state
						gen matchpoint = 1
						compress
					save RFSRX_tempziptrans_`batch', replace
				
				frame change default
					
					use in `firstaddress'/`lastaddress' using RFSRX_FullListingPlatform_Properties_Short_wStrings, clear
						drop ams_zip
						gen matchpoint = 1
						compress
						
					joinby matchpoint using RFSRX_tempziptrans_`batch'
					drop matchpoint
			
					if _N>0{
						
							timer on 1
							gen byte str_dist = (ams_street_short!=rx_street_short)
							timer off 1
							timer list
							timer clear
							
							timer on 1
							gen byte str_dist_numeric = (ams_street_numeric!=rx_street_numeric)
							timer off 1
							timer list
							timer clear
							
							keep if str_dist==0 | str_dist_numeric==0
						if _N>0{
							
								timer on 1
								gen byte str_dist_alpha = (ams_street_alpha!=rx_street_alpha)									
								timer off 1
								timer list
								timer clear
								
								keep if str_dist==0 | (str_dist_alpha==0 & str_dist_numeric==0)
						}
						
					
					if _N>0{
						
						save RFSRX_tempresults_`batch', replace
						
						frame change MatchResults
						append using RFSRX_tempresults_`batch'

						if mod(`i',10)==0 {
								save RFSRX_LPMatches_`batch', replace
							}
							
						
							
						}
					}
			}
			
			frame change MatchResults

				
			save RFSRX_LPMatches_`batch', replace
		
	}
	
	frame change default
	frame drop RXListings
	frame drop RXListings2
	frame drop MatchResults
	frame drop Zips
		
		
			clear
	forvalues batch=1(1)16 {
			append using RFSRX_LPMatches_`batch'
		}
		
			rename ams_id lp_ams_id
			
			merge m:1 ams_id_short using RFSRX_Addresses_RX_Short_amslookup
					drop if _merge==2
					drop _merge ams_id_short
					
			rename ams_id rx_ams_id
		

			keep lp_ams_id rx_ams_id
				
			duplicates drop
			
			compress
	
		save RFSRX_FinalLPMatch, replace

		use id ams_id list_date agent_id agent_code agent_name sell_agent_id sell_agent_code sell_agent_name using RX_FullListingPlatform_Listings, clear
		
			gen length=strlen(agent_name)
			summ length
			local thelength = r(max)
			recast str`thelength' agent_name
			drop length
			
			gen length=strlen(agent_code)
			summ length
			local thelength = r(max)
			recast str`thelength' agent_code
			drop length
			
			gen length=strlen(agent_id)
			summ length
			local thelength = r(max)
			recast str`thelength' agent_id
			drop length
			
			preserve
				
				keep id agent_name agent_code agent_id
		
				rename id lp_id
				
				merge 1:1 lp_id using RX_RedXAgents
					drop if _merge==2
					drop _merge
				
				rename lp_id id
				
				drop id
				
				collapse (max) redx_agent, by(agent_name agent_code agent_id)
				
				drop if agent_name=="" & agent_code=="" & agent_id==""
				
				gen redx_agent_agg_old = redx_agent
				gen redx_agent_agg_new = redx_agent

				local deltas = 1
				local loopcount = 0
				
				while `deltas' > 0 & `loopcount'<=30 {
		 
					replace redx_agent_agg_old = redx_agent_agg_new
					
					by agent_name, sort: egen redx_agent_agg1=max(redx_agent_agg_old) if agent_name!=""
					by agent_code, sort: egen redx_agent_agg2=max(redx_agent_agg_old) if agent_code!=""
					by agent_id, sort: egen redx_agent_agg3=max(redx_agent_agg_old) if agent_id!=""
					
					replace redx_agent_agg_new = max(redx_agent_agg1,redx_agent_agg2,redx_agent_agg3)
					
					drop redx_agent_agg1 redx_agent_agg2 redx_agent_agg3
					
					count if redx_agent_agg_old==. & redx_agent_agg_new==1
					
					local deltas = r(N)
					local loopcount = `loopcount' + 1
					
					disp "In Loop `loopcount' there were `deltas' deltas found"
					
				}
				
				drop redx_agent_agg_old
				
				rename redx_agent_agg_new redx_agent2

				drop redx_agent
				
				keep if redx_agent2==1
				
				sort agent_id agent_code agent_name
				
				compress
			save RFSRX_LPAgentsThatAreRedX, replace
				
			restore
			
			drop id
		
		drop if ams_id==""
		
		preserve
			
			drop sell_agent_id sell_agent_code sell_agent_name
			
				compress
			save RFSRX_FullListingPlatform_ActiveAgents_01, replace
			
				keep agent_id agent_code agent_name
				
				duplicates drop
				
				drop if agent_name=="" & agent_code=="" & agent_id==""
				
				sort agent_name agent_code agent_id
				
				
				gen myagentnum = _n


				gen myagentnum_old = myagentnum
				gen myagentnum_new = myagentnum

				local deltas = 1
				local loopcount = 1
				
				while `deltas' > 0 & `loopcount'<=1 {

					replace myagentnum_old = myagentnum_new
					
					by agent_name, sort: egen myagentnum_agg1=min(myagentnum_old) if agent_name!=""
					by agent_code, sort: egen myagentnum_agg2=min(myagentnum_old) if agent_code!=""
					by agent_id, sort: egen myagentnum_agg3=min(myagentnum_old) if agent_id!=""
					
					gen myagentnum_`loopcount' = min(myagentnum_agg1,myagentnum_agg2,myagentnum_agg3,myagentnum_old)
					
					replace myagentnum_new = myagentnum_`loopcount'
					
					drop myagentnum_agg1 myagentnum_agg2 myagentnum_agg3
					
					count if myagentnum_old!=myagentnum_new
					
					local deltas = r(N)
					
					disp "In Loop `loopcount' there were `deltas' deltas found"
					
					local loopcount = `loopcount' + 1
					
				}
				
				replace myagentnum = myagentnum_new
				drop myagentnum_*
				
				by myagentnum, sort: gen counter=_n
				replace counter = . if counter>1
				gen counter2=sum(counter)
				drop myagentnum counter
				rename counter2 agent_uniquenum
				
				compress
				
			save RFSRX_FullListingPlatform_ActiveAgents_03, replace
			
				gen strlen=strlen(agent_name)
				su strlen
				
				local maxlength_aa3 = r(max)
			
		restore
		
		
			
				drop agent_id agent_code agent_name
				
				gen length=strlen(sell_agent_name)
				summ length
				local thelength = r(max)
				recast str`thelength' sell_agent_name
				drop length
				
				gen length=strlen(sell_agent_code)
				summ length
				local thelength = r(max)
				recast str`thelength' sell_agent_code
				drop length
				
				gen length=strlen(sell_agent_id)
				summ length
				local thelength = r(max)
				recast str`thelength' sell_agent_id
				drop length
		
				
				rename sell_agent_code agent_code
				rename sell_agent_id agent_id
				rename sell_agent_name agent_name
					
					compress
				save RFSRX_FullListingPlatform_BuyersAgentsWorking, replace
				
					gen strlen=strlen(agent_name)
					drop if strlen > `maxlength_aa3'
					*264
					drop strlen
					compress agent_name

				merge m:1 agent_id agent_code agent_name using RFSRX_FullListingPlatform_ActiveAgents_03
					keep if _merge==3
					drop _merge
					
				keep ams_id list_date agent_uniquenum
				
				rename agent_uniquenum agent_uniquenum_buyeragent
				
				drop if list_date==.
				
				duplicates drop
			

				rename ams_id lp_ams_id
						
						
				joinby lp_ams_id using RFSRX_FinalLPMatch
					
					drop lp_ams_id
					
					compress
				save RFSRX_Leads_BuyersAgents, replace
		
use RFSRX_FullListingPlatform_ActiveAgents_01, clear
		
		merge m:1 agent_id agent_code agent_name using RFSRX_LPAgentsThatAreRedX
			drop if _merge==2
			drop _merge 
		
		gen byte agent2 = 1
			replace redx_agent2 = 0 if redx_agent2==.
			
			drop agent_id agent_code agent_name
			
		duplicates drop

		
		collapse (max) agent2 redx_agent2, by(ams_id list_date)
		
		compress
		
		preserve
			drop agent2
				
			save RFSRX_AgentCompAnalysis_RedXAgents, replace
			*in at 1346
		restore
		
		
		collapse (max) agent2 redx_agent2, by(ams_id)
		
		compress
		
	save RFSRX_Agent2Indicator_LPPop, replace

		use RFSRX_FinalLPMatch, clear
		
			rename lp_ams_id ams_id
		
			merge m:1 ams_id using RFSRX_Agent2Indicator_LPPop
				drop if _merge==2
				drop _merge ams_id
			
				replace agent2 = 0 if agent2==.
				replace redx_agent2 = 0 if redx_agent2==.

			
			rename rx_ams_id ams_id
		
			duplicates drop

			collapse (max) agent2 redx_agent2, by(ams_id)
		
				compress
		save RFSRX_Agent2Indicator, replace 
		
		
		use agent_name using RFSRX_LPAgentsThatAreRedX, clear
		
			gen strlen=strlen(agent_name)
			su strlen
			
			local maxlength_listagentsredx = r(max)

		use RFSRX_FullListingPlatform_BuyersAgentsWorking, clear
					
					gen strlen=strlen(agent_name)
					*255
					drop if strlen > `maxlength_listagentsredx'
					drop strlen
					compress agent_name
					
					
					merge m:1 agent_id agent_code agent_name using RFSRX_LPAgentsThatAreRedX
						drop if _merge==2
						
				
					
					gen redxbuyeragent = 0
						replace redxbuyeragent = 1 if _merge==3
					
					gen nonredxbuyeragent = 0
						replace nonredxbuyeragent = 1 if !(agent_name=="" & agent_code=="" & agent_id=="") & redxbuyeragent==0
					
					keep ams_id redxbuyeragent nonredxbuyeragent
					
					collapse (max) redxbuyeragent nonredxbuyeragent, by(ams_id)
					
					duplicates drop
				
						compress
				
					save RFSRX_BuyerAgentsThatAreRedX, replace
			
		
		erase RFSRX_FullListingPlatform_BuyersAgentsWorking.dta

	use RFSRX_FinalLPMatch, clear
			
				rename lp_ams_id ams_id
				
				joinby ams_id using RFSRX_BuyerAgentsThatAreRedX
		
					drop ams_id
					
					
				rename rx_ams_id ams_id
				
				duplicates drop
				
				collapse (max) redxbuyeragent nonredxbuyeragent, by(ams_id)
				
			compress
		save RFSRX_BuyAgentRedXIndicator, replace

	use ams_id list_date modified_at list_price list_price_original using RX_FullListingPlatform_Listings, clear

		drop if ams_id=="" | list_date==.
		
		preserve
			
			duplicates drop

			joinby ams_id using RFSRX_ZLPMatch_Results

			keep importparcelid list_date ams_id
			
			order importparcelid list_date
			
			rename list_date lp_list_date
			
			format %td lp_list_date
			
			keep if lp_list_date>=20454 & lp_list_date<=21396
			
			drop ams_id
			
			gen lp_list_year = year(lp_list_date)
			gen lp_list_month = month(lp_list_date)
			
			by importparcelid lp_list_year lp_list_month, sort: egen min_lp_list_date=min(lp_list_date)
			
			drop lp_list_date
			
			duplicates drop
			
			compress
			save RFSRX_ListCharComp_LPListDates, replace
			
		restore

		replace list_price = . if !inrange(list_price,30000,2000000)
		replace list_price_original = . if !inrange(list_price_original,30000,2000000)
		
		preserve

				sort ams_id list_date modified_at

				order ams_id list_date modified_at

				by ams_id list_date (modified_at), sort: gen double counter=_n if list_price_original<.
				by ams_id list_date, sort: egen double mincounter=min(counter) if list_price_original<.
					gen list_price_original_master = list_price_original if counter==mincounter
				by ams_id list_date, sort: egen list_price_original_master1=max(list_price_original_master)
				replace list_price_original=list_price_original_master1
					drop counter mincounter list_price_original_master list_price_original_master1

				by ams_id list_date, sort: egen double minmoddate=min(modified_at)
					gen list_price_original_master = list_price if minmoddate==modified_at & list_price_original==.
				by ams_id list_date, sort: egen list_price_original_master1=max(list_price_original_master)
				replace list_price_original=list_price_original_master1 if list_price_original==.
					drop minmoddate list_price_original_master list_price_original_master1


				gen price_date = dofc(modified_at)
					format %td price_date
					drop modified_at

				order ams_id list_date price_date
				
				sort ams_id list_date price_date
				
				duplicates drop
				
				compress
				
				expand 2, gen(counter)
				
				replace price_date = list_date if counter==1
				replace list_price = list_price_original if counter==1
				
				drop list_price_original
				
				duplicates drop
				
				drop if list_price==.

				drop counter
				
				keep ams_id list_date list_price
				
				duplicates drop
				
				gen byte pricecount = 1

				collapse (sum) pricecount, by(ams_id list_date)
			
				compress
			save RFSRX_ListPriceRevisions, replace
			
		restore

			 by ams_id list_date, sort: egen double minmoddate=min(modified_at)
				replace list_price = . if !(modified_at==minmoddate)
				drop minmoddate 

			 drop if list_price==. & list_price_original==.

			 by ams_id list_date (modified_at), sort: gen double counter=_n if list_price_original<.
			 by ams_id list_date, sort: egen double mincounter=min(counter) if list_price_original<.
				replace list_price_original = . if mincounter!=counter
				drop counter mincounter modified_at

			drop if list_price==. & list_price_original==.

			by ams_id list_date, sort: egen replacewith=min(list_price_original)
				replace list_price_original = replacewith if list_price_original==.
				drop replacewith

			gen byte missingorigprice = 0
				replace missingorigprice = 1 if list_price_original==.

			replace list_price_original = list_price if list_price_original==.
				drop list_price

			duplicates drop

			by ams_id list_date, sort: egen counter=total(1)
				drop if counter>1 & missingorigprice==1
				drop counter
                
			joinby ams_id using RX_FullListingPlatform_Properties
				drop ams_street ams_city ams_dpbc longitude latitude property_id land_val estimated_value property_type transfer_price transfer_date num_garages
				drop num_units num_bath year_built
				
			duplicates drop

				replace ams_state = "" if !(ams_state=="AK" |  ams_state=="AL" |  ams_state=="AR" |  ams_state=="AZ" |  ams_state=="CA" |  ams_state=="CO" |  ams_state=="CT" |  ams_state=="DC" |  ams_state=="DE" |  ams_state=="FL" |  ams_state=="GA" |  ams_state=="HI" |  ams_state=="IA" |  ams_state=="ID" |  ams_state=="IL" |  ams_state=="IN" |  ams_state=="KS" |  ams_state=="KY" |  ams_state=="LA" |  ams_state=="MA" |  ams_state=="MD" |  ams_state=="ME" |  ams_state=="MI" |  ams_state=="MN" |  ams_state=="MO" |  ams_state=="MS" |  ams_state=="MT" |  ams_state=="NC" |  ams_state=="ND" |  ams_state=="NE" |  ams_state=="NH" |  ams_state=="NJ" |  ams_state=="NM" |  ams_state=="NV" |  ams_state=="NY" |  ams_state=="OH" |  ams_state=="OK" |  ams_state=="OR" |  ams_state=="PA" |  ams_state=="RI" |  ams_state=="SC" |  ams_state=="SD" |  ams_state=="TN" |  ams_state=="TX" |  ams_state=="UT" |  ams_state=="VA" |  ams_state=="VT" |  ams_state=="WA" |  ams_state=="WI" |  ams_state=="WV" |  ams_state=="WY")
			
				replace num_bed = . if num_bed<=0 | num_bed>10


				replace sq_ft = . if !inrange(sq_ft,600,10000)


			duplicates drop

				by ams_id, sort: egen modezip = mode(ams_zip)
				by ams_id, sort: egen modecounty = mode(ams_county)
				by ams_id, sort: egen modestate = mode(ams_state)
				
				by ams_id, sort: egen meanbed = mean(num_bed)
				by ams_id, sort: egen meansqft = mean(sq_ft)

				
				replace ams_zip = modezip if modezip<.
				replace ams_county = modecounty if modecounty<.
				replace ams_state = modestate if modestate!=""
				
				replace num_bed = round(meanbed,1) if meanbed<.

				replace sq_ft = round(meansqft,1) if meansqft<.

				
				drop mode* mean* 
			
			duplicates drop

			gen listyear = year(list_date)
			gen listmonth = month(list_date)
			
			by ams_id listyear listmonth (list_date), sort: gen counter = _n
				drop if counter>1
				drop counter
			
			drop if ams_zip==. | ams_zip==0
			
			replace ams_county = . if ams_county==0
			
				by ams_zip, sort: egen modalcounty=mode(ams_county)
				by ams_zip, sort: egen modalstate=mode(ams_state)
				
				replace ams_county = modalcounty if ams_county==.
				replace ams_state = modalstate if ams_state==""
				
				drop modalcounty modalstate
				
			replace ams_county = 0 if ams_county==.
			
			drop if ams_state==""
			
			gen origlistprice = list_price_original

			
			by ams_state ams_county listyear, sort: egen countyyear_lp_p1=pctile(origlistprice), p(1)
			by ams_state ams_county listyear, sort: egen countyyear_lp_p99=pctile(origlistprice), p(99)
				replace origlistprice = . if origlistprice<countyyear_lp_p1 | origlistprice>countyyear_lp_p99
				drop countyyear_lp_p1 countyyear_lp_p99
				drop ams_state ams_county

			
			gen log_olp=log(origlistprice)
			
			drop origlistprice
			
			
			
			gen fe_beds = num_bed
				replace fe_beds=6 if fe_beds>6 & fe_beds<.
				replace fe_beds=0 if fe_beds==.
				drop num_bed
				
			gen fe_sqft = round(sq_ft,5)/5
				replace fe_sqft = 0 if fe_sqft==.
				drop sq_ft

			compress
			

 			reghdfe log_olp, absorb(ams_zip##listyear##listmonth##fe_beds##fe_sqft) resid
				rename _reghdfe_resid log_olp_resid
	
			
			
			reghdfe log_olp, absorb(ams_zip##listyear listyear##listmonth ams_zip##fe_beds ams_zip##fe_sqft) resid
				rename _reghdfe_resid log_olp_resid_b
				drop log_olp ams_zip listyear listmonth fe_beds fe_sqft

				rename ams_id lp_ams_id
			
			
			
			joinby lp_ams_id using RFSRX_FinalLPMatch, unm(both)
				tab _merge
				drop if _merge==2
				drop _merge
			
			
			
			rename lp_ams_id ams_id
			
			gen byte redxlead = 0
				replace redxlead = 1 if rx_ams_id!=""
			
			sort ams_id rx_ams_id list_date
			
				compress

			preserve
			
				keep rx_ams_id list_price_original log_olp_resid log_olp_resid_b list_date redxlead
			
				keep if redxlead==1
				drop redxlead

				rename rx_ams_id ams_id
			
						compress
				save RFSRX_RedXLeadsFirstLPListPrice, replace

		
			restore
		
		keep ams_id redxlead list_price_original list_date
		
			merge m:1 ams_id using RFSRX_FullListingPlatform_LatLons
				keep if _merge==3
				drop _merge
				
			drop ams_zip
	
			preserve
				keep if redxlead==0
				drop redxlead
				
				gen byte matchpoint = 1
				
				rename list_date nonredx_list_date
				rename list_price_original nonredx_price
				rename lp_lat nonredx_lat
				rename lp_lon nonredx_lon
				
					compress
				save RFSRX_FirstListPrice_NonRedX, replace
				
				
			restore
			
			keep if redxlead==1
				drop redxlead
			
			rename list_date redx_list_date
			rename list_price_original redx_price
			rename lp_lat redx_lat
			rename lp_lon redx_lon
			

 			save RFSRX_FirstListPrice_RedX, replace

	use importparcelid createdatetime using RFSRX_STMerge_01, clear
		
		
		gen createdate = dofc(createdatetime)
			format %td createdate
			
		drop createdatetime
		
		order importparcelid createdate
		
		rename createdate rx_list_date
		
		keep if rx_list_date>=20454 & rx_list_date<=21396
		
		gen rx_list_year = year(rx_list_date)
		gen rx_list_month = month(rx_list_date)
		
		drop rx_list_date
		
		duplicates drop
	
		drop rx_list_year rx_list_month
		
		gen rx_listing = 1
		
		collapse (sum) rx_listing, by(importparcelid)
		
			compress
	save RFSRX_ListCharComp_RXListings, replace
	
	use importparcelid recordingdate using RX_ZTRAX_DatesandCodes, clear
	
			duplicates drop
			
			sort importparcelid recordingdate
			
				compress
		save RFSRX_ZTRAX_PropertyLevelTransactionDates, replace
	
	use transid importparcelid prop_beds prop_baths w_asmt_sqft_calc propertyaddresslatitude propertyaddresslongitude propertyzip fips prop_buildage_full proptype prop_sqftbuckets prop_lotsizebuckets prop_buildage prop_noofstories using RX_ZTRAX, clear
		
		preserve
			keep transid importparcelid prop_beds prop_baths w_asmt_sqft_calc propertyaddresslatitude propertyaddresslongitude propertyzip fips proptype prop_sqftbuckets prop_lotsizebuckets prop_buildage prop_noofstories  
				compress
			save RFSRX_ZW_Trans_PropDets, replace

		restore
		
		drop transid proptype prop_sqftbuckets prop_lotsizebuckets prop_buildage prop_noofstories  
		
		by importparcelid, sort: egen prop_buildage_full_avg=mean(prop_buildage_full)
				drop prop_buildage_full
		
		duplicates drop
		
		preserve
				
				sort importparcelid
				by importparcelid, sort: egen counter=total(1)
				drop if counter>1
				drop counter
					compress
			save RFSRX_PropertyCharsForListingAnalysis, replace
			
		restore
		
 		keep importparcelid prop_beds prop_baths w_asmt_sqft_calc prop_buildage_full_avg

		
		duplicates drop
		
		sort importparcelid
		
			compress
	save RFSRX_Full_Short, replace
	
	use RFSRX_ListCharComp_LPListDates, clear
		
		
		joinby importparcelid using RFSRX_ListCharComp_RXListings, unm(both)
			tab _merge
			drop if _merge==2
			replace rx_listing = 0 if rx_listing==.
			replace rx_listing = 1 if rx_listing>1 & rx_listing<.
			drop _merge

		joinby importparcelid using RFSRX_ZTRAX_PropertyLevelTransactionDates, unm(both)
			tab _merge

			drop if _merge==2
			drop _merge
			
		gen timeonmarket = (recordingdate-min_lp_list_date)
			drop min_lp_list_date
		
		preserve
			
			keep importparcelid recordingdate timeonmarket
			
			keep if timeonmarket>0
			
			duplicates drop
			
			collapse (min) timeonmarket, by(importparcelid recordingdate)
			
				compress
			save RFSRX_PropTimeOnMarkets, replace
			
		restore
		
		gen qs = 0
			replace qs = 1 if timeonmarket<=60 & timeonmarket>0
			
		collapse (max) qs, by(importparcelid lp_list_year lp_list_month  rx_listing)

		merge m:1 importparcelid using RFSRX_PropertyCharsForListingAnalysis
			drop if _merge==2
			drop _merge
			drop importparcelid 
			
		
			replace prop_beds = 0 if prop_beds == .

			gen prop_sqftbuckets = floor(w_asmt_sqft_calc/5)*5
				replace prop_sqftbuckets = 0 if prop_sqftbuckets==.
				drop w_asmt_sqft_calc

			compress
		save RFSRX_ListingPlatformQuickSaleAnalysis, replace
	
	use ams_id lead_id createdate using RX_Leads, clear
			rename createdate createdatetime
		gen createdate = dofc(createdatetime)
			format %td createdate
		
		keep ams_id lead_id createdate
		
		compress
		
	save RFSRX_DatedAgents_Leads, replace
	
	use lead_id ams_id list_date using RX_LP, clear
	
		drop if ams_id==""
	
		
		duplicates drop
	
		joinby lead_id ams_id using RFSRX_DatedAgents_Leads
		
		
			gen lp_daysuntillist = list_date - createdate if list_date>=createdate
			
		drop list_date
		
		
		collapse (min) lp_daysuntillist, by(lead_id ams_id createdate)
		
		
		compress
	save RFSRX_LPEventDates, replace
	
	use ams_id using RX_LP, clear
		
		drop if ams_id==""

		duplicates drop

		gen byte agent = 1
		
		compress
	save RFSRX_AgentInd, replace
	
		clear
	insheet using ZIP_COUNTY_032018.csv, comma
		compress
	save zip_county, replace
		
	use RX_Leads, clear
		
		drop area_name year_built lot_size city latitude longitude
		
			replace square_feet = strlower(square_feet)
			replace square_feet = subinstr(square_feet," ","",.)
			
			replace square_feet = subinstr(square_feet,"sq.ft.","",.)
			replace square_feet = subinstr(square_feet,"sq.ft","",.)
			replace square_feet = subinstr(square_feet,"sqft","",.)
			replace square_feet = subinstr(square_feet,"sqf","",.)
			replace square_feet = subinstr(square_feet,"sf","",.)
			replace square_feet = subinstr(square_feet,"sq","",.)
			
			destring square_feet, replace force
		winsor square_feet, gen(w_square_feet) p(.01)
		gen sqftbuckets = round(w_square_feet,10)/10
		replace sqftbuckets = 0 if sqftbuckets==.
		drop square_feet w_square_feet
		
			replace bedrooms = subinstr(bedrooms,"BED","",.)
			replace bedrooms = subinstr(bedrooms,",","",.)
			replace bedrooms = subinstr(bedrooms,"½",".5",.)
			replace bedrooms = subinstr(bedrooms,"Â","",.)
			replace bedrooms = subinstr(bedrooms,"MUST","",.)
			replace bedrooms = subinstr(bedrooms," ","",.)
		destring bedrooms, replace
		
		replace bedrooms = 0 if bedrooms==.
		replace bedrooms = 4 if bedrooms > 4
		
			replace bathrooms = subinstr(bathrooms,"Â","",.)
			replace bathrooms = subinstr(bathrooms,"½",".5",.)
			replace bathrooms = subinstr(bathrooms,"BEAUT","",.)
			replace bathrooms = subinstr(bathrooms,"MYRTL","",.)
			replace bathrooms = subinstr(bathrooms,"SHARE","",.)
			replace bathrooms = subinstr(bathrooms,"SPLIT","",.)
			replace bathrooms = subinstr(bathrooms,"x","",.)
			replace bathrooms = subinstr(bathrooms,"-",".",.)
			replace bathrooms = subinstr(bathrooms,"`",".",.)
			replace bathrooms = subinstr(bathrooms,"+","",.)
			replace bathrooms = subinstr(bathrooms,"-",".",.)
			replace bathrooms = subinstr(bathrooms," ","",.)
		destring bathrooms, replace
		
		replace bathrooms = 2*round(bathrooms,.5)
		replace bathrooms = 0 if bathrooms==.
		replace bathrooms = 6 if bathrooms>6
		
		replace garage = garage*2
		replace garage = 0 if garage==.
		
		merge m:1 zip using zip_county
			drop if _merge==2
			drop _merge
		
			rename createdate createdatetime
		gen createdate = dofc(createdatetime)
			format %td createdate

		gen createmonth=month(createdate)
		
		order lead_id ams_id state county zip product createmonth createdate createdatetime bedrooms bathrooms garage sqftbuckets data_source street
		
		encode state, gen(nstate)
			order nstate, after(state)
		
		
		merge m:1 ams_id using RFSRX_AgentInd
			drop if _merge==2
			drop _merge
		
		
			replace agent = 0 if agent==.
		
			merge 1:1 lead_id ams_id createdate using RFSRX_LPEventDates
				drop if _merge==2
				drop _merge
			
			
		compress
	save RFSRX_Experiments, replace
	
	use lead_id createdate using RFSRX_Experiments, clear
		compress
	save RFSRX_LeadDates, replace
	
	use transid importparcelid recordingdate salespriceamount intrafamilytransferflag using RX_ZTRAX_DatesandCodes, clear
	
			
			preserve
			
				merge m:1 importparcelid using RFSRX_STMerge_01_UniqueZID
					keep if _merge==3
					drop _merge
					compress
				save RFSRX_STMerge_02, replace
					keep importparcelid
					duplicates drop
				save RFSRX_STMerge_02_UniqueRXID, replace
				
				
			restore
			
			drop intrafamilytransferflag
			
			preserve
				
				keep transid salespriceamount importparcelid recordingdate
				
				duplicates drop
		
				by transid, sort: egen counter=total(1)
				
				keep if counter==1
				drop counter
				
				merge 1:1 transid importparcelid using RFSRX_ZW_Trans_PropDets
					keep if _merge==3
					drop _merge
				
				drop if salespriceamount<=100
				drop if salespriceamount==.
				
				
				
				gen tranyear = year(recordingdate)
				gen tranmonth = month(recordingdate)
				
				by fips tranyear, sort: egen countyyear_sp_p1=pctile(salespriceamount), p(1)
				by fips tranyear, sort: egen countyyear_sp_p99=pctile(salespriceamount), p(99)
					replace salespriceamount = . if salespriceamount<countyyear_sp_p1 | salespriceamount>countyyear_sp_p99
				gen lsp = ln(salespriceamount)
				

				replace prop_sqftbuckets = round(prop_sqftbuckets*5,100)

					compress
				save RFSRX_PreHedonics, replace		

				reghdfe lsp, absorb(prop_sqftbuckets##propertyzip##tranyear##prop_beds##tranmonth) resid
					predict resid_salesprice, resid
				
					gen zip3 = floor(propertyzip/100)
					gen tranquarter = floor((tranmonth-1)/4)+1
				
				reghdfe lsp, absorb(zip3##tranyear##tranquarter##prop_beds) resid
					predict resid_salesprice_big, resid
		
				
					keep transid resid_*
					drop if resid_salesprice==. & resid_salesprice_big==.
				
					compress
				save RFSRX_Hedonics_Residuals, replace
				
			restore
			
			
			merge m:1 transid using RFSRX_Hedonics_Residuals
				keep if _merge==3
				drop _merge
				
			joinby importparcelid using RFSRX_AddressMatchResults, unm(both)
				tab _merge
				drop if _merge==2
				
			preserve
				
					drop if _merge==1
					drop _merge
				
				merge m:1 lead_id using RFSRX_LeadDates
					keep if _merge==3
					drop _merge
			
				duplicates drop
				
				order lead_id createdate importparcelid transid recordingdate resid_salesprice resid_salesprice_big
				
				gen daydiff = recordingdate - createdate
				
				keep if daydiff>0
				
				by lead_id, sort: egen mindaydiff=min(daydiff)
				
				keep if daydiff==mindaydiff
				
				keep lead_id resid_salesprice
				
				duplicates drop
				
				rename resid_salesprice focal_resid_salesprice
				
				by lead_id, sort: egen counter=total(1)
					drop if counter>1
					drop counter
				
					compress
				save RFSRX_Hedonics_FocalResiduals, replace
				
			restore
			
				drop _merge
				
			merge m:1 importparcelid recordingdate using RFSRX_PropTimeOnMarkets
				drop if _merge==2
				drop _merge
				
			keep transid recordingdate lead_id salespriceamount timeonmarket resid_salesprice resid_salesprice_big
			
			preserve
				
				keep lead_id recordingdate salespriceamount timeonmarket resid_salesprice resid_salesprice_big
				
				drop if lead_id==. | (resid_salesprice==. & resid_salesprice_big==.)
					drop resid_salesprice resid_salesprice_big
				
				merge m:1 lead_id using RFSRX_LeadDates
					keep if _merge==3
					drop _merge
				
				duplicates drop
				
				gen daydiff = recordingdate - createdate
				
				keep if daydiff>0
				
				by lead_id, sort: egen mindaydiff=min(daydiff)
				
				keep if daydiff==mindaydiff
				
				keep lead_id salespriceamount timeonmarket
				
				duplicates drop
				
				by lead_id, sort: egen counter=total(1)
				drop if counter>1
				drop counter
				
					compress
				save RFSRX_LeadResids, replace
				
			restore

			drop if transid==. | (resid_salesprice==. & resid_salesprice_big==.)
			
			drop lead_id resid_salesprice resid_salesprice_big
			
			joinby transid using RFSRX_ProximateTransactions, unm(both)
				tab _merge
				keep if _merge==3
				drop _merge
			

			rename salespriceamount proxtran_salesprice

			rename timeonmarket proxtran_timeonmarket
			
			merge m:1 lead_id using RFSRX_LeadResids
				keep if _merge==3
				drop _merge
				

			rename salespriceamount focaltran_saleprice

			rename timeonmarket focaltran_timeonmarket
			

			collapse (mean) meanproctranprice=proxtran_salesprice meanproctrantom=proxtran_timeonmarket, by(lead_id focaltran_saleprice focaltran_timeonmarket)
			
			gen diffinmean_price = focaltran_saleprice - meanproctranprice
			
			gen diffinmean_tom = focaltran_timeonmarket - meanproctrantom
			
			
	save RFSRX_ProximateListings_B, replace

	use RFSRX_STMerge_01, clear
			merge m:1 importparcelid using RFSRX_STMerge_02_UniqueRXID
				keep if _merge==3
				drop _merge
		
		joinby importparcelid using RFSRX_STMerge_02
			order createdatetime, after(ams_id)

				replace intrafamilytransferflag = "0" if intrafamilytransferflag==" "
				replace intrafamilytransferflag = "0" if intrafamilytransferflag==""
				replace intrafamilytransferflag = "1" if intrafamilytransferflag=="Y"
				replace intrafamilytransferflag = "1" if intrafamilytransferflag=="y"
				destring intrafamilytransferflag, replace
	
			order recordingdate intrafamilytransferflag, after(importparcelid)

		gen double createdate = dofc(createdatetime)
				format createdate %td
				order createdate, after(ams_id)
				
		sort ams_id createdate importparcelid recordingdate
			format recordingdate %td
			
		preserve
			
			
			merge m:1 transid using RFSRX_Hedonics_Residuals
				drop if _merge==2
				drop _merge
				
			drop if recordingdate>createdate
			
			drop if intrafamilytransferflag==1
			
			by ams_id createdate, sort: egen lastrecordingdate=max(recordingdate)
				replace lastrecordingdate=(lastrecordingdate==recordingdate)
				keep if lastrecordingdate==1
				drop lastrecordingdate
			
			replace salespriceamount=. if salespriceamount==0
			
			gen tenureinhome = createdate - recordingdate
			
			collapse (mean) salespriceamount resid_salesprice (max) intrafamilytransferflag (firstnm) recordingdate tenureinhome, by(ams_id createdate)

			keep ams_id createdate salespriceamount tenureinhome resid_salesprice
			
			rename salespriceamount purchaseprice
			rename resid_salesprice purchaseprice_resid
			
				compress
			save RFSRX_PurchasePrices, replace
			
		restore
		
		drop if recordingdate<createdate

		
		by ams_id createdate, sort: egen nextrecordingdate=min(recordingdate)
			replace nextrecordingdate=(nextrecordingdate==recordingdate)
			keep if nextrecordingdate==1
			drop nextrecordingdate
		
		replace salespriceamount=. if salespriceamount==0
		
		preserve
			keep ams_id createdatetime transid
			duplicates drop
			save RFSRX_STMerge_transids, replace
		restore
		
		collapse (mean) salespriceamount (max) intrafamilytransferflag (firstnm) recordingdate, by(ams_id createdate)
		
		compress
	save RFSRX_STMerge_03, replace
	
	use transid salespriceamount using RFSRX_PreHedonics, clear

		keep if salespriceamount<.
		
		joinby transid using RFSRX_STMerge_transids
		
		drop transid
		
		by ams_id createdatetime, sort: egen counter=total(1)
		
		drop if counter>1
		
		drop counter
		
		compress
	save RFSRX_CleanedSalesPrices, replace
	
	
	use importparcelid prop_beds w_asmt_sqft_calc using RFSRX_ZW_Trans_PropDets, clear

		
		replace w_asmt_sqft_calc = . if w_asmt_sqft_calc==0
		winsor w_asmt_sqft_calc, gen(w_square_feet) p(.01)
			drop w_asmt_sqft_calc
			
 		replace prop_beds = . if prop_beds<=0
		rename prop_beds zw_beds
		rename w_square_feet zw_sqft
		drop if zw_beds==. & zw_sqft==.
		
		duplicates drop
		
		sort importparcelid
		compress
	save RFSRX_PropChars, replace

			local batches = 16
			forvalues batch = 1(1)`batches' {
	
			frame change default
			
			clear all
			
			frame create RXAddresses2

			frame create RXAddresses
			frame change RXAddresses
			
			use RFSRX_ZTS_RXAddresses, clear
				drop createdate
			
			frame create PCSResults
			frame change PCSResults
			
			gen long importparcelid = .
			gen long lead_id = .
			gen double geo_dist = .
		
			frame create Zips
			frame change Zips
			
			use RFSRX_PCS_Zips, clear
				
				local N = _N
				
				local last = floor(min(`batch'*`N'/`batches',`N'))
				local first = floor(min(`batch'*`N'/`batches'+1-`N'/`batches',`N'))
				
				if `first'==`last' & `last'==`N'{
					disp "You did too many batches!!"
					disp "if there are exactly 1000*n+1 zips then you need to do the last row manually"
					crashmenow
				}
				
				forvalues i = `first'/`last' {
					frame change Zips
					
					local zip = zip[`i']
					local firstaddress = firstaddress[`i']
					local lastaddress = lastaddress[`i']
					
					disp `zip'
					disp "Doing zip number `i' for batch `batch' going from `first' to `last' out of total `N'"
					disp "From `firstaddress' to `lastaddress'"
					display c(current_time)
				
					frame drop RXAddresses2 
					frame copy RXAddresses RXAddresses2
					frame change RXAddresses2
					
						keep if rx_zip==`zip'
							drop rx_zip
							gen matchpoint = 1
							compress
						save RFSRX_tempziptrans_`batch', replace
					
					frame change default
						
						use in `firstaddress'/`lastaddress' using RFSRX_ZTS_ZTRAX_Props, clear
							drop z_zip
							gen matchpoint = 1
							compress
							
						joinby matchpoint using RFSRX_tempziptrans_`batch'
						drop matchpoint
				
						if _N>0{
							
							timer on 1
							geodist z_lat z_lon rx_lat rx_lon, gen(geo_dist) miles sphere
							timer off 1
							timer list
							timer clear

							keep importparcelid lead_id geo_dist
								order importparcelid lead_id geo_dist
							
							keep if geo_dist<=.25
						
						if _N>0{
						
							frame change PCSResults
								myfrappend _all, from(default)
								if mod(`i',10)==0 {
									save RFSRX_PCS_Results_`batch', replace
								}
							}
						}
				}
				
				frame change PCSResults
				save RFSRX_PCS_Results_`batch', replace
				
				frame change default
				frame drop RXAddresses2
				frame drop RXAddresses
				frame drop PCSResults
				frame drop Zips
		
		}
		
		clear
		frame create working
		
		forvalues batch = 1/16 {
			
			frame change working
			
			use RFSRX_PCS_Results_`batch', clear
				
				keep if geo_dist<=.25
					drop geo_dist
				
				merge m:1 importparcelid using RFSRX_PropChars
					drop if _merge==2
					drop _merge
					
				drop importparcelid
				
				merge m:1 lead_id using RFSRX_LeadPropChars
					drop if _merge==2
					drop _merge
			
					
				gen byte lead_lt_beds = 0 if zw_beds<. & rx_beds<.
					replace lead_lt_beds = 1 if rx_beds<zw_beds & zw_beds<. & rx_beds<.

				gen byte lead_lt_sqft = 0 if zw_sqft<. & rx_sqft<.
					replace lead_lt_sqft = 1 if rx_sqft<zw_sqft & zw_sqft<. & rx_sqft<.
			
				
				collapse (mean) lead_lt_beds lead_lt_sqft, by(lead_id)
				
					compress
				save temp_deleteme, replace
				
				frame change default
				append using temp_deleteme
		}
		
			compress
		save RFSRX_PropCharDistros_025, replace
		
		frame drop working
	
	use RFSRX_FullListingPlatform_ActiveAgents_01, clear

		merge m:1 agent_id agent_code agent_name using RFSRX_FullListingPlatform_ActiveAgents_03
			keep if _merge==3
			drop _merge
			
		keep ams_id list_date agent_uniquenum
		
		drop if list_date==.
		
		duplicates drop
		
		compress
		
	save RFSRX_FullListingPlatform_ActiveAgents_04, replace
	
	
	use ams_id list_date id sold_date sold_price list_price_original using RX_FullListingPlatform_Listings, clear
		
		drop if ams_id==""

		sort ams_id list_date
		
		replace sold_price = . if sold_price==0
		replace list_price_original = . if list_price_original==0
		
		drop if list_date==.
		
		gen listpricemissing = 0
			replace listpricemissing = 1 if list_price_original==.
		
		by ams_id list_date (listpricemissing id), sort: gen list_price = list_price_original[1]
		
		drop listpricemissing list_price_original
		
		gen soldindicator = 0
			replace soldindicator = 1 if (sold_date>list_date & sold_date<.) | sold_price<.
			
		by ams_id list_date, sort: egen sold = max(soldindicator)
		
		drop soldindicator
		
		gen sold_date_privileged = sold_date if sold_price<. & sold_date>list_date
		
		format %td sold_date_privileged
		
		gen sold_date_subordinated = sold_date if sold_price==. | (sold_price<. & sold_date<=list_date)
		
		format %td sold_date_subordinated
		
		drop sold_date
		
		gen sold_price_missing = 0
			replace sold_price_missing = 1 if sold_price==.
		by ams_id list_date (sold_price_missing id), sort: replace sold_price=sold_price[1]
			drop sold_price_missing
			
		gen sold_date_privileged_missing = 0
			replace sold_date_privileged_missing = 1 if sold_date_privileged==.
		by ams_id list_date (sold_date_privileged_missing id), sort: replace sold_date_privileged=sold_date_privileged[1]
			drop sold_date_privileged_missing
			
		gen sold_date_subordinated_missing = 0
			replace sold_date_subordinated_missing = 1 if sold_date_subordinated==.
		by ams_id list_date (sold_date_subordinated_missing id), sort: replace sold_date_subordinated=sold_date_subordinated[1]
			drop sold_date_subordinated_missing
			
		drop id
		
		duplicates drop
		
		gen sold_date = sold_date_privileged
			replace sold_date = sold_date_subordinated if sold_date==.
			
		drop sold_date_privileged sold_date_subordinated
		
		
		duplicates drop
		
		replace sold_date = . if sold_date<list_date

			
		replace sold_date = . if sold==0 & sold_date<. & sold_price==.
		replace sold_price = . if sold==0 & sold_date==. & sold_price<.
			drop sold_date sold
		

		gen saletolistpricerat = sold_price/list_price
			drop sold_price list_price

		keep ams_id list_date saletolistpricerat

		compress
	save RFSRX_Agent_Performance, replace	
	
	use RFSRX_FullListingPlatform_ActiveAgents_04, clear
			
			preserve
				
				rename ams_id lp_ams_id
	
				joinby lp_ams_id using RFSRX_FinalLPMatch
				
				drop lp_ams_id
				
					compress
				save RFSRX_Agent_FarSmall_01, replace
				
			restore
			
			merge m:1 ams_id using RFSRX_FullListingPlatform_LatLons
				drop if _merge==2
				drop _merge
				
				drop ams_zip
			
			preserve
				
				keep if lp_lat<. & lp_lon<.
		
				keep agent_uniquenum lp_lat lp_lon ams_id list_date
				
				duplicates drop
				
				keep agent_uniquenum lp_lat lp_lon list_date
				
				sort agent_uniquenum
				
				rename list_date listing_list_date
				
					compress
				save RFSRX_LocalListings_AgentListings, replace
				
			restore
			
			merge m:1 ams_id list_date using RFSRX_Agent_Performance
				drop if _merge==2
				drop _merge
			
			gen validloc = 0
				replace validloc = 1 if lp_lat<.

			keep ams_id list_date agent_uniquenum lp_lat lp_lon validloc saletolistpricerat

			
				compress
		save RFSRX_AgentCharacteristicsJump_01, replace
			
			keep agent_uniquenum
			
			duplicates drop
		
			compress
		save RFSRX_Agent_FarSmall, replace

	
	use RFSRX_Agent_FarSmall_01, clear

		rename agent_uniquenum agent_uniquenum_selleragent
		
		joinby rx_ams_id list_date using RFSRX_Leads_BuyersAgents
		
		gen sameagent = 0
			replace sameagent = 1 if agent_uniquenum_selleragent==agent_uniquenum_buyeragent
			
		collapse (mean) sameagent, by(rx_ams_id list_date)
		
		gen anysameagent = 0
			replace anysameagent = 1  if sameagent>0
			
		compress
	save RFSRX_SameAgents, replace
	
	
	
	use lead_id ams_id createdate using RFSRX_Experiments, clear
	
			rename ams_id rx_ams_id
			
			preserve
				
				joinby rx_ams_id using RFSRX_Agent_FarSmall_01
			
				gen afterdate = 0
					replace afterdate = 1 if list_date>createdate
				
				by lead_id, sort: egen hasafterdate=max(afterdate)
				
				by lead_id, sort: egen maxdate=max(list_date)
					format %td maxdate
					
				replace afterdate = 1 if hasafterdate==0 & maxdate==list_date
				
				keep if afterdate==1
				
				drop afterdate hasafterdate maxdate
				
				by lead_id, sort: egen mindate=min(list_date)
				
				keep if list_date==mindate
				drop mindate
						
				compress
			save RFSRX_AgentIntermediateFramework, replace
				
				gen daydiff = list_date - createdate
				
				keep lead_id agent_uniquenum daydiff
				
				merge m:1 agent_uniquenum using RFSRX_Agent_FarSmall
					keep if _merge==3
					drop _merge
				
				rename daydiff agent_farsmalllisting_daydiff
				
				by lead_id, sort: egen agent_uniquenum_counter=total(1)
				
				drop agent_uniquenum
				
				order lead_id agent_uniquenum_counter agent_farsmalllisting_daydiff
				

				keep lead_id agent_uniquenum_counter agent_farsmalllisting_daydiff
				
				duplicates drop
			
					compress
				save RFSRX_FarSmallAgents, replace
					
			restore
			
			joinby rx_ams_id using RFSRX_SameAgents
			
			gen afterdate = 0
				replace afterdate = 1 if list_date>createdate
			
			by lead_id, sort: egen hasafterdate=max(afterdate)
			
			by lead_id, sort: egen maxdate=max(list_date)
				format %td maxdate
				
			replace afterdate = 1 if hasafterdate==0 & maxdate==list_date
			
			keep if afterdate==1
			
			drop afterdate hasafterdate maxdate
			
			by lead_id, sort: egen mindate=min(list_date)
			
			keep if list_date==mindate
			drop mindate list_date

			
			keep lead_id anysameagent
			
				compress
			save RFSRX_Leads_SameAgents, replace

			use lead_id agent_uniquenum list_date rx_ams_id using RFSRX_AgentIntermediateFramework, clear
			
			
			
			duplicates drop
			
			merge m:1 lead_id using RFSRX_LeadLocs
				drop if _merge==2
				drop _merge
				
			preserve
			
				
						rename list_date rxlead_lp_list_date
		
						joinby agent_uniquenum using RFSRX_AgentCharacteristicsJump_01
						
						drop if rx_ams_id==ams_id
						
						gen byte pastlisting = 0
							replace pastlisting = 1 if list_date<rxlead_lp_list_date
						
						by lead_id agent_uniquenum, sort: egen agentchar_listcount_past=total(validloc*pastlisting)
						
						by lead_id agent_uniquenum, sort: egen agentchar_lnsaletolist_past=mean(ln(saletolistpricerat)) if pastlisting==1
						
						by lead_id agent_uniquenum, sort: egen agentchar_meanlat_past=mean(lp_lat) if pastlisting==1
						by lead_id agent_uniquenum, sort: egen agentchar_meanlon_past=mean(lp_lon) if pastlisting==1
						
						geodist lp_lat lp_lon agentchar_meanlat_past agentchar_meanlon_past if pastlisting==1, sphere miles gen(agentchar_listdist_past)
						
						by lead_id agent_uniquenum, sort: egen agentchar_avglistdist_past=mean(agentchar_listdist_past) if pastlisting==1
						
						collapse (mean) agentchar_listcount_past agentchar_lnsaletolist_past agentchar_avglistdist_past agentchar_meanlat_past agentchar_meanlon_past, by(lead_id rx_lat rx_lon)
						
						geodist rx_lat rx_lon agentchar_meanlat_past agentchar_meanlon_past, sphere miles gen(agentchar_leaddistfromagent_past)

						
						keep lead_id  agentchar_lnsaletolist_past agentchar_avglistdist_past agentchar_leaddistfromagent_past agentchar_listcount_past
						
							compress
						save RFSRX_AgentCharacteristicsJump_03, replace	

			
			restore
			
			drop rx_ams_id
			
			duplicates drop
			
			joinby agent_uniquenum using RFSRX_LocalListings_AgentListings
			
			drop agent_uniquenum
			
			geodist rx_lat rx_lon lp_lat lp_lon, gen(geo_dist) sphere miles
			
			drop rx_lat rx_lon lp_lat lp_lon
			
			gen byte pastlist = 0
				replace pastlist = 1 if listing_list_date<list_date
			
			
			
			drop if geo_dist>2

			gen byte agentpastlisting_025 = 0

			replace agentpastlisting_025 = 1 if geo_dist<=.25 & pastlist==1
			
			drop geo_dist pastlist
			
			collapse (sum) agentpastlisting_025 , by(lead_id)
			
				compress
			save RFSRX_LocalListings, replace 
	
	
	frame create results
		forvalues batch = 1/16 {
			
			use lead_id transid trancount_m90_025 using RFSRX_HedTrans_Results_UnCollapsed_`batch', clear
			
			drop if trancount_m90_025==0
			
			merge m:1 transid using RFSRX_Hedonics_Residuals
				keep if _merge==3
				drop _merge transid
			
			gen double resid_salesprice_m90_025 = resid_salesprice if trancount_m90_025==1
				
			drop resid_salesprice trancount_m90_025
			

			collapse (mean) resid_salesprice_m90_025, by(lead_id)
				
				compress
			save temp_deleteme, replace
				
			frame change results
				append using temp_deleteme
			frame change default
			
		}
	frame change results
		save RFSRX_Hedonics_SpilloverResiduals, replace
	frame change default
	frame drop results
	
	
	use RFSRX_Experiments, clear

		
		merge m:1 ams_id using RFSRX_STMerge_01_MergedRedXRecords
			drop if _merge==2
			gen zillowmatched = 0
				replace zillowmatched = 1 if _merge==3
				drop _merge

		merge m:1 ams_id createdate using RFSRX_STMerge_03
			drop if _merge==2
			drop _merge
			
	
		drop intrafamilytransferflag

		gen timeonmarket = (recordingdate-createdate)
			drop recordingdate
		
		
		gen salehazard365 = 0
			replace salehazard365 = 1 if timeonmarket<=365

		gen logsales = ln(salespriceamount)

			gen createyear=year(createdate)
			gen cm=createyear*12+createmonth-24192
				drop if cm>=32 
			
			gen week=week(createdate)
			
			egen cw=group(week createyear)
				drop week createyear

			drop if county==.

			gen tuy=strpos(street,"0")+strpos(street,"1")+strpos(street,"2")+strpos(street,"3")+strpos(street,"4")+strpos(street,"5")+strpos(street,"6")+strpos(street,"7")+strpos(street,"8")+strpos(street,"9")
				drop street
				
			gen num=0
			replace num=1 if tuy>0 & tuy<.
				drop tuy

				drop if num!=1

				
			g twogarage=0 if garage>0
				replace twogarage=1 if garage>=4
				drop garage

			
			merge 1:1 lead_id using RFSRX_ZTS_Results
				drop if _merge==2
				drop _merge
				
			merge 1:1 lead_id using RFSRX_ListingPlatformSearch_Results
				drop if _merge==2
				drop _merge
			
			
			
			merge 1:1 lead_id using RFSRX_Hedonics_SpilloverResiduals
				drop if _merge==2
				drop _merge
			
				
				
			merge 1:1 lead_id using RFSRX_Hedonics_FocalResiduals
				drop if _merge==2
				drop _merge
			
				
				
			merge m:1 ams_id using RFSRX_Agent2Indicator
				drop if _merge==2
				replace agent2 = 0 if _merge==1
				replace redx_agent2 = 0 if _merge==1
				drop _merge
				

				replace bedrooms = round(bedrooms,1)
				replace sqftbuckets = round(sqftbuckets,10)
				

			
			merge 1:1 lead_id using RFSRX_BrokeredTransactions
				drop if _merge==2
				drop _merge

				
			merge 1:1 lead_id using RFSRX_FarSmallAgents
				drop if _merge==2
				drop _merge
			
		
			drop salespriceamount
			merge m:1 ams_id createdatetime using RFSRX_CleanedSalesPrices
				drop if _merge==2
				drop _merge
			
			
		
			merge m:1 ams_id using RFSRX_BuyAgentRedXIndicator
				drop if _merge==2
				drop _merge
				
			replace redxbuyeragent = 0 if redxbuyeragent==.
			replace nonredxbuyeragent = 0 if nonredxbuyeragent==.
			
			
			
			gen byte somelistedagent = 0
				replace somelistedagent =1 if redxbuyeragent==1 | nonredxbuyeragent==1
				drop nonredxbuyeragent
			
			gen lsqft=log(sqftbuckets)
			
			sort createdatetime lead_id

			gen new=0
				replace new=1 if nstate!=nstate[_n-1] | createdatetime!=createdatetime[_n-1] | product!=product[_n-1] | data_source!=data_source[_n-1]
				
				drop data_source
				
			gen totnew=sum(new)

			
			egen zur=group(createdate state product) if totnew<.
			by zur, sort: egen ziprank=rank(lead_id) if zur<., field
			by zur, sort: egen zursize=max(ziprank) if zur<.
				drop zur
			
			
			
			gen iqip = (-ln(ziprank))/ln(3)
			
			gen frbo = 0 if product<.
				replace frbo=1 if product==1
					
			
			
				gen lpagent = 0
					replace lpagent = 1 if agent2==1 & lp_daysuntillist<.
					
				gen lpagent_redx = 0
					replace lpagent_redx = 1 if redx_agent2==1 & lp_daysuntillist<.
					
				gen lpagent_noredx = 0
					replace lpagent_noredx = 1 if lpagent==1 & lpagent_redx==0 & lp_daysuntillist<.
						
				gen lpagent_win5days = lpagent
					replace lpagent_win5days = 0 if lp_daysuntillist>5
					
				gen lpagent_win3days = lpagent
					replace lpagent_win3days = 0 if lp_daysuntillist>3
			

				gen agent_multipleagents = 0 if agent_uniquenum_counter==1
					replace agent_multipleagents = 1 if agent_uniquenum_counter>1 & agent_uniquenum_counter<.
					drop agent_uniquenum_counter
					
				g rat=((trancount_m90_025)/(listcount_m90_025))
					drop trancount_m90_025 listcount_m90_025
				sum rat, d
				g wrat=min(max(rat,r(p1)),r(p99)) if rat<.
					drop rat
				
				gen salehazard = 0
					replace salehazard = 1 if timeonmarket<.
					
				gen longsale=0
					replace longsale=1 if timeonmarket<. & timeonmarket>730
			
			
					sum focal_resid_salesprice, d
				gen mainpricevar=max(min(focal_resid_salesprice,r(p99)),r(p1)) if focal_resid_salesprice <.

					sum resid_salesprice_m90_025, d
				gen pricecontrol=max(min(resid_salesprice_m90_025,r(p99)),r(p1)) if resid_salesprice_m90_025 <.
					drop resid_salesprice_m90_025
		
				
				gen listcountfecontrol=round((listcount_other_m90_025)/(listcount_other_m90_200),0.01)
					drop listcount_other_m90_200
				gen trancountfecontrol=round((trancount_oth_cl_m90_025)/(trancount_oth_cl_m90_200),0.01)
					drop trancount_oth_cl_m90_200
				
				gen brokcontrol = brok_trancount_oth_cl_m90_025/trancount_oth_cl_m90_025
					drop brok_trancount_oth_cl_m90_025
			
				
		
	
		gen qs = 0
			replace qs = 1 if timeonmarket<=60 & timeonmarket>0
		drop timeonmarket
		
		replace bathrooms = bathrooms/2
		
		gen logpredictedprice = logsales - focal_resid_salesprice
		
		merge m:1 lead_id using RFSRX_AgentCharacteristicsJump_03
			drop if _merge==2
			drop _merge
		
			
		merge 1:1 lead_id using RFSRX_LocalListings
			drop if _merge==2
			drop _merge
		
		gen byte area_newagent_025 = 0 if agentpastlisting_025<.

		
		replace area_newagent_025 = 1 if agentpastlisting_025==0


			drop agentpastlisting_025

		gen ln_agentchar_leaddist_past = ln(agentchar_leaddistfromagent_past)
			drop agentchar_leaddistfromagent_past
		gen ln_agentchar_dispersion_past = ln(agentchar_avglistdist_past)
			drop agentchar_avglistdist_past
			
		merge 1:1 lead_id using RFSRX_Leads_SameAgents
			drop if _merge==2
			drop _merge

		
		reghdfe mainpricevar iqip pricecontrol if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
			gen sample_sales = 1 if e(sample)
		
		
		
		
		merge 1:1 lead_id using RFSRX_PropCharDistros_025
			drop if _merge==2
			drop _merge
		
		
		
		gen tran_list_rat = trancount_oth_cl_m90_025/listcount_other_m90_025
			replace tran_list_rat = 100 if listcount_other_m90_025==0 & trancount_oth_cl_m90_025>0 & trancount_oth_cl_m90_025<.
				drop trancount_oth_cl_m90_025 listcount_other_m90_025

			su tran_list_rat if sample_sales==1, de
		gen thickmarket = 0 if sample_sales==1 & (tran_list_rat >= r(p50) & tran_list_rat<.)
			replace thickmarket = 1 if sample_sales==1 & tran_list_rat < r(p50)
				drop tran_list_rat
		
		gen double bedtails = abs(lead_lt_beds-.5) if sample_sales==1
		gen thickbeds = 0 if bedtails<.
			replace thickbeds = 1 if bedtails<.3
			drop bedtails lead_lt_beds
		
		gen double sqfttails = abs(lead_lt_sqft-.5) if sample_sales==1
		gen thicksqft = 0 if sqfttails<.
			replace thicksqft = 1 if sqfttails<.3
			drop sqfttails lead_lt_sqft
		
			
		foreach topdate in 30 60 90 120 150 180 270 365 {
			gen ratlist_`topdate' = (listcount_other_`topdate'_025)/(listcount_other_`topdate'_200)
			gen rattran_`topdate' = (trancount_oth_cl_`topdate'_025)/(trancount_oth_cl_`topdate'_200)
		}
			drop listcount_other_30_025 listcount_other_60_025 listcount_other_120_025 listcount_other_150_025
			drop listcount_other_30_200 listcount_other_60_200 listcount_other_120_200 listcount_other_150_200
			drop trancount_oth_cl_30_025 trancount_oth_cl_60_025 trancount_oth_cl_120_025 trancount_oth_cl_150_025
			drop trancount_oth_cl_30_200 trancount_oth_cl_60_200 trancount_oth_cl_120_200 trancount_oth_cl_150_200
		
		gen salesprice_1000s = salespriceamount/1000
			drop salespriceamount
		
		by totnew, sort: egen totnewsize=total(1)

		reghdfe lpagent_redx iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
			gen sample_full = 1 if e(sample)
			
		preserve
			
			keep if sample_full==1
			keep ams_id
			
			duplicates drop
			
				compress
			save RFSRX_FocalAMSIDs, replace
			
		restore
		
			gen relativerank = ziprank/zursize
		astile rankquartiles = relativerank if sample_full==1, nquant(4)
			drop relativerank zursize
		
		gen topquartile = 0 if sample_full==1
			replace topquartile = 1 if sample_full==1 & rankquartiles<2
		
		gen vacantland = 1 if sample_full==1 & bedrooms==0 & bathrooms==0 & sqftbuckets==0 & product==2
			replace vacantland = 0 if sample_full==1 & vacantland==.
		
		gen onebedroom = 0 if bedrooms > 0
				replace onebedroom = 1 if bedrooms == 1
		
		gen ratlist_90_180 = (listcount_other_180_025-listcount_other_90_025)/(listcount_other_180_200-listcount_other_90_200)
		gen ratlist_180_270 = (listcount_other_270_025-listcount_other_180_025)/(listcount_other_270_200-listcount_other_180_200)
		gen ratlist_270_365 = (listcount_other_365_025-listcount_other_270_025)/(listcount_other_365_200-listcount_other_270_200)
			drop listcount_other_90_025 listcount_other_180_025 listcount_other_270_025 listcount_other_365_025
			drop listcount_other_90_200 listcount_other_180_200 listcount_other_270_200 listcount_other_365_200

		gen rattran_90_180 = (trancount_oth_cl_180_025-trancount_oth_cl_90_025)/(trancount_oth_cl_180_200-trancount_oth_cl_90_200)
		gen rattran_180_270 = (trancount_oth_cl_270_025-trancount_oth_cl_180_025)/(trancount_oth_cl_270_200-trancount_oth_cl_180_200)
		gen rattran_270_365 = (trancount_oth_cl_365_025-trancount_oth_cl_270_025)/(trancount_oth_cl_365_200-trancount_oth_cl_270_200)
			drop trancount_oth_cl_90_025 trancount_oth_cl_180_025 trancount_oth_cl_270_025 trancount_oth_cl_365_025
			drop trancount_oth_cl_90_200 trancount_oth_cl_180_200 trancount_oth_cl_270_200 trancount_oth_cl_365_200
		
		compress
	save RFSRX_LeadsMain, replace

		drop state nstate zip createmonth createdatetime bedrooms bathrooms sqftbuckets agent lp_daysuntillist salehazard365 logsales twogarage focal_resid_salesprice agent2 redx_agent2 agent_farsmalllisting_daydiff redxbuyeragent somelistedagent lsqft new ziprank frbo lpagent_redx lpagent_noredx lpagent_win5days lpagent_win3days agent_multipleagents wrat salehazard longsale mainpricevar pricecontrol listcountfecontrol trancountfecontrol brokcontrol qs logpredictedprice agentchar_listcount_past agentchar_lnsaletolist_past area_newagent_025 ln_agentchar_leaddist_past ln_agentchar_dispersion_past anysameagent sample_sales thickmarket thickbeds thicksqft ratlist_30 rattran_30 ratlist_60 rattran_60 ratlist_90 rattran_90 ratlist_120 rattran_120 ratlist_150 rattran_150 ratlist_180 rattran_180 ratlist_270 rattran_270 ratlist_365 rattran_365 salesprice_1000s sample_full rankquartiles topquartile vacantland onebedroom ratlist_90_180 ratlist_180_270 ratlist_270_365 rattran_90_180 rattran_180_270 rattran_270_365
		
		joinby ams_id using RFSRX_RedXLeadsFirstLPListPrice
		
		gen datediff = list_date - createdate
		
		replace datediff = . if datediff<=0
		
		duplicates drop
		
		sort lead_id ams_id list_date list_price_original log_olp_resid_b log_olp_resid   
		
			set seed 19851985
			gen rnum = runiform()
		by lead_id (datediff rnum), sort: gen counter=_n
			drop rnum
		
		keep if counter==1 & datediff<.
		
		drop counter datediff
		
		
		merge m:1 ams_id createdate using RFSRX_PurchasePrices
			drop if _merge==2
			drop _merge
		
		
		gen listtopurch = list_price_original/purchaseprice
			drop list_price_original purchaseprice
		gen log_listtopurch = log(listtopurch)
			drop listtopurch
		
		gen logtenureinhome = log(tenureinhome)
			drop tenureinhome
		
		merge m:1 ams_id list_date using RFSRX_ListPriceRevisions
			drop if _merge==2
			drop _merge

		
		drop ams_id
		
		gen byte listpricechange = 0 if pricecount<.
			replace listpricechange = 1 if pricecount>1 & pricecount<.
			drop pricecount
			
		
			compress
	save RFSRX_BehavioralMain, replace
	
	
	
	
	use RFSRX_ProximateLPListings, clear

		joinby ams_id using RFSRX_ZLPMatch_Results
		
		keep importparcelid list_date lead_id
		
			
		preserve
			drop list_date
			
			duplicates drop
			
				compress
			save RFSRX_RedXLeadIds_to_ProximateLPListingImportparcels, replace
			
			
		restore
		
		drop lead_id
		
		order importparcelid list_date
		
		rename list_date lp_list_date
		
		format %td lp_list_date
		
		keep if lp_list_date>=20454 & lp_list_date<=21396
		
		gen lp_list_year = year(lp_list_date)
		gen lp_list_month = month(lp_list_date)
		
		drop lp_list_date
		
		duplicates drop

 		compress
 	save RFSRX_ListCharComp_ProximateLPListDates, replace
	
	
	use RFSRX_ListCharComp_ProximateLPListDates, clear
		
		drop lp_list_year lp_list_month
		
		gen lp_listing = 1
		
		collapse (sum) lp_listing, by(importparcelid)
		
			compress
	save RFSRX_ListCharComp_ProximateLPListings, replace
	
	use RFSRX_ListCharComp_RXListings, clear
	
		append using RFSRX_ListCharComp_ProximateLPListings
		
		replace lp_listing = 0 if lp_listing==.
		replace rx_listing = 0 if rx_listing==.
		
		collapse (sum) lp_listing rx_listing, by(importparcelid)
	
		
		merge 1:1 importparcelid using RFSRX_Full_Short
			keep if _merge==3
			drop _merge
			
			
		rename lp_listing lp_listing_count
		rename rx_listing rx_listing_count
		
			
		gen rx_listing = 0
			replace rx_listing=1 if rx_listing_count>0 & rx_listing_count<.
	
		gen lp_only_listing = 0
			replace lp_only_listing=1 if lp_listing_count>0 & lp_listing_count<. & rx_listing_count==0
			drop lp_listing_count rx_listing_count
			
		replace prop_baths = prop_baths/2

		compress
	save RFSRX_ProximateAgentListings, replace
	
		joinby importparcelid using RFSRX_Leads_Importparcelids, unm(master)
			tab _merge
			drop _merge
		
		rename lead_id rxlisting_lead_id
		
		joinby importparcelid using RFSRX_RedXLeadIds_to_ProximateLPListingImportparcels, unm(master)
			tab _merge
			drop _merge
			
		rename lead_id proximateto_lead_id
		
		expand 2, gen(counter)
		
		gen double lead_id = proximateto_lead_id if counter == 0
		replace lead_id = rxlisting_lead_id if counter == 1
		
		drop counter proximateto_lead_id rxlisting_lead_id
		
		
		order importparcelid lead_id rx_listing
		
		drop if lead_id==.
		
		duplicates drop

		merge m:1 importparcelid lead_id using RFSRX_Leads_Importparcelids
			drop if _merge==2
			gen byte rx_listing_focal = 1 if _merge==3
				replace rx_listing_focal = 0 if _merge==1
			drop _merge	
			
		order lead_id rx_listing rx_listing_focal importparcelid
		sort lead_id rx_listing rx_listing_focal importparcelid
		
		format %10.0f lead_id
		
		by lead_id, sort: egen counter=total(1)
			drop if counter==1
			drop counter
			
		by lead_id, sort: egen counter=total(rx_listing_focal)
			keep if counter==1
			drop counter
			
		drop rx_listing
		
		collapse (mean) prop_beds prop_baths w_asmt_sqft_calc prop_buildage_full_avg, by(lead_id rx_listing_focal)
		
		gen beds_fsbo = prop_beds if rx_listing_focal==1
		gen baths_fsbo = prop_baths if rx_listing_focal==1
		gen sqft_fsbo = w_asmt_sqft_calc if rx_listing_focal==1
		gen age_fsbo = prop_buildage_full_avg if rx_listing_focal==1
		
		gen beds_proximate = prop_beds if rx_listing_focal==0
		gen baths_proximate = prop_baths if rx_listing_focal==0
		gen sqft_proximate = w_asmt_sqft_calc if rx_listing_focal==0
		gen age_proximate = prop_buildage_full_avg if rx_listing_focal==0
		
		drop prop_beds prop_baths w_asmt_sqft_calc prop_buildage_full_avg rx_listing_focal
		
		collapse (firstnm) beds_fsbo baths_fsbo sqft_fsbo age_fsbo beds_proximate baths_proximate sqft_proximate age_proximate, by(lead_id)
		
		gen beds_diff = beds_fsbo - beds_proximate
			drop beds_fsbo beds_proximate
		gen baths_diff = baths_fsbo - baths_proximate
			drop baths_fsbo baths_proximate
		gen sqft_diff = sqft_fsbo - sqft_proximate
			drop sqft_fsbo sqft_proximate
		gen age_diff = age_fsbo - age_proximate
			drop age_fsbo age_proximate
    
		
	save RFSRX_ProximateListings_A, replace

			frame change default
			
			use RFSRX_FirstListPrice_RedX, clear
			
				preserve
					
					keep redx_price ams_id
					gen double redxrownum=_n
					
					merge m:1 ams_id using RFSRX_FocalAMSIDs
						drop if _merge==2
						gen byte focalobs = 1 if _merge==3
						drop _merge
					
							compress
					save RFSRX_RedXRowNum, replace
					
				restore
			
				local maxrows = _N
				
				local batchnum = "01"
				local startrow = 1
				local endrow = `maxrows'
				
				drop ams_id
				
				frame create lookupvalues
				frame change lookupvalues
				
				use RFSRX_FirstListPrice_NonRedX, clear
				
				frame copy lookupvalues working
				
				frame copy default results
				frame change results
				
				gen long nonredx_price = redx_price
				drop redx_list_date redx_lat redx_lon
				gen long redxrownum = .
				
				drop if 1==1
				
				forvalues row = `startrow'/`endrow' {
					
					frame change default
					
					local price = redx_price[`row']
					local date = redx_list_date[`row']
					local lat = redx_lat[`row']
					local lon = redx_lon[`row']
					
					frame change working
					
					keep if inrange(nonredx_list_date - `date',1,365)
					
			
					drop nonredx_list_date
					
					if _N > 0 {
					    
						geodist nonredx_lat nonredx_lon `lat' `lon', gen(geodist) sphere miles
					
						keep if geodist<.25
						
						drop geodist
						
					}

					drop nonredx_lat nonredx_lon
					
					if _N > 0 {
					
						gen long redx_price = `price'
						gen long redxrownum = `row'
						
						save temp_FLPMatching_`batchnum', replace
						
						frame change results
						
							append using temp_FLPMatching_`batchnum'
							
						frame change working
						
					
					}
					
					frame change default
					
					
					frame drop working
					frame copy lookupvalues working
					
					disp "Finished Row `row' of `startrow' to `endrow'"
					
				}
					
				frame change results
				
					compress
				save RFSRX_FirstListPrice_Matching_`batchnum', replace
				
				frame change default
				frame drop results
				frame drop working
				frame drop lookupvalues
	
		clear all
	foreach batch in 01 {
		
		append using RFSRX_FirstListPrice_Matching_`batch'
		
	}
			
			collapse (mean) nonredx_price, by(redxrownum redx_price)
			
			rename redx_price redx_price_good
			
			merge 1:1 redxrownum using RFSRX_RedXRowNum
				drop if _merge==2
				drop _merge
				drop ams_id
			
			count if redx_price_good!=redx_price
			
			drop redx_price_good
			
			keep if focalobs==1
				drop focalobs
			
			gen diffinmean_listprice = redx_price - nonredx_price
				drop redx_price nonredx_price
			
	save RFSRX_ProximateListings_C, replace

	
	use RFSRX_FullListingPlatform_ActiveAgents_04, clear

		merge m:1 ams_id using RFSRX_FullListingPlatform_LatLons
			keep if _merge==3
			drop _merge
		
		drop ams_zip
		
		merge m:1 ams_id list_date using RFSRX_Agent_Performance
			drop if _merge==2
			drop _merge
			
			
		by agent_uniquenum, sort: egen listcounter=rank(list_date), track
		gen agent_listcount_validloc_past = listcounter - 1
			drop listcounter
		
		gen log_saletolistpricerat = log(saletolistpricerat)
			drop saletolistpricerat

		by agent_uniquenum (list_date), sort: gen numerator=sum(log_saletolistpricerat)
		by agent_uniquenum list_date, sort: gen counter=_n
		by agent_uniquenum list_date, sort: egen counter2=total(1)
			replace counter = . if counter2==1
			drop counter2
		gen newnumerator = numerator[_n-1] if agent_uniquenum==agent_uniquenum[_n-1] & counter==1
		by agent_uniquenum list_date, sort: egen newnumerator2 = max(newnumerator)
			replace numerator = newnumerator2 if newnumerator2<.
			replace numerator = 0 if newnumerator2==. & counter<.
			replace numerator = numerator - log_saletolistpricerat if counter==. & log_saletolistpricerat<.
			drop counter newnumerator newnumerator2
		gen byte popped = 0
			replace popped = 1 if log_saletolistpricerat<.
		by agent_uniquenum (list_date), sort: gen denominator=sum(popped)
		by agent_uniquenum list_date, sort: gen counter=_n
		by agent_uniquenum list_date, sort: egen counter2=total(1)
			replace counter = . if counter2==1
			drop counter2
		gen newndenominator = denominator[_n-1] if agent_uniquenum==agent_uniquenum[_n-1] & counter==1
		by agent_uniquenum list_date, sort: egen newndenominator2 = max(newndenominator)
			replace denominator = newndenominator2 if newndenominator2<.
			replace denominator = 0 if newndenominator2==. & counter<.
			replace denominator = denominator - popped if counter==.
			drop counter newndenominator newndenominator2
		gen agent_avg_lnsaletolist_past = numerator/denominator
			drop numerator denominator popped
		
		sort agent_uniquenum list_date

		by agent_uniquenum (list_date), sort: gen numerator=sum(lp_lat)
		by agent_uniquenum list_date, sort: gen counter=_n
		by agent_uniquenum list_date, sort: egen counter2=total(1)
			replace counter = . if counter2==1
			drop counter2
		gen newnumerator = numerator[_n-1] if agent_uniquenum==agent_uniquenum[_n-1] & counter==1
		by agent_uniquenum list_date, sort: egen newnumerator2 = max(newnumerator)
			replace numerator = newnumerator2 if newnumerator2<.
			replace numerator = 0 if newnumerator2==. & counter<.
			replace numerator = numerator - lp_lat if counter==.
			drop counter newnumerator newnumerator2
		gen avgagentlat_past = numerator/agent_listcount_validloc_past
			drop numerator
		
		by agent_uniquenum (list_date), sort: gen numerator=sum(lp_lon)
		by agent_uniquenum list_date, sort: gen counter=_n
		by agent_uniquenum list_date, sort: egen counter2=total(1)
			replace counter = . if counter2==1
			drop counter2
		gen newnumerator = numerator[_n-1] if agent_uniquenum==agent_uniquenum[_n-1] & counter==1
		by agent_uniquenum list_date, sort: egen newnumerator2 = max(newnumerator)
			replace numerator = newnumerator2 if newnumerator2<.
			replace numerator = 0 if newnumerator2==. & counter<.
			replace numerator = numerator - lp_lon if counter==.
			drop counter newnumerator newnumerator2
		gen avgagentlon_past = numerator/agent_listcount_validloc_past
			drop numerator

		geodist lp_lat lp_lon avgagentlat_past avgagentlon_past, sphere miles gen(geo_dist_past)
			drop avgagentlat_past avgagentlon_past
		
		by agent_uniquenum (list_date), sort: gen numerator=sum(geo_dist_past)
		by agent_uniquenum list_date, sort: gen counter=_n
		by agent_uniquenum list_date, sort: egen counter2=total(1)
			replace counter = . if counter2==1
			drop counter2
			
		gen newnumerator = numerator[_n-1] if agent_uniquenum==agent_uniquenum[_n-1] & counter==1
		
		by agent_uniquenum list_date, sort: egen newnumerator2 = max(newnumerator)
			replace numerator = newnumerator2 if newnumerator2<.
			replace numerator = 0 if newnumerator2==. & counter<.
			replace numerator = numerator - geo_dist_past if counter==.
			drop counter newnumerator newnumerator2
		
		gen agent_dist_avg_past = numerator/agent_listcount_validloc_past
			drop numerator
	
		merge m:1 ams_id list_date using RFSRX_AgentCompAnalysis_RedXAgents
			keep if _merge==3
			drop _merge 
		
			compress
		save RFSRX_AgentCompAnalysis_HoldFile, replace	
		
				keep agent_uniquenum ams_id list_date lp_lat lp_lon
			
				sort agent_uniquenum ams_id list_date lp_lat lp_lon
						
		save RFSRX_LocalListings_AllAnalysis_01, replace

				gen double rownum = _n
				
				keep agent_uniquenum rownum
				
				collapse (min) minrownum=rownum (max) maxrownum=rownum, by(agent_uniquenum)
				
				
				frame copy default agentnums
					
			use RFSRX_LocalListings_AllAnalysis_01, clear
					
				keep ams_id list_date agent_uniquenum
				
				drop if 1==1
				
				gen byte agentpastlisting_025 = 1
			
					
				frame copy default results
						
				frame change agentnums
				
				local maxrownum = _N
				
				forvalues agentrow = 1/`maxrownum' {
					
					local agentuniquenumber = agent_uniquenum[`agentrow']
					local minrownumber = minrownum[`agentrow']
					local maxrownumber = maxrownum[`agentrow']
					
					frame change default
					
					use in `minrownumber'/`maxrownumber' using RFSRX_LocalListings_AllAnalysis_01, clear
					quietly save RFSRX_LocalListings_tempfile1, replace
					
					rename list_date focal_list_date
					rename lp_lat focal_lat
					rename lp_lon focal_lon
					rename ams_id focal_ams_id
					
					joinby agent_uniquenum using RFSRX_LocalListings_tempfile1
					
					quietly drop if ams_id==focal_ams_id
					drop ams_id
					rename focal_ams_id ams_id
					
					quietly drop if list_date>=focal_list_date
					drop list_date
					rename focal_list_date list_date
					
					local howmany = _N
					
					if `howmany' > 0 {
					
						geodist lp_lat lp_lon focal_lat focal_lon, sphere miles gen(geo_dist)
					
						quietly drop if geo_dist>2
					
						drop lp_lat lp_lon focal_lat focal_lon
					
						quietly gen byte agentpastlisting_025 = 1 if geo_dist<=.25
					
						
						local howmany2 = _N
					
						if `howmany2' > 0 {
						
							collapse (sum) agentpastlisting_025, by(ams_id list_date agent_uniquenum)
							
							quietly save RFSRX_LocalListings_tempfile2, replace
							
							frame change results
						
							append using RFSRX_LocalListings_tempfile2
						
						}
						
					}

					frame change agentnums
					
					local percentage = floor(1000*(`agentrow'/`maxrownum'))/10
					
					disp "Completed `percentage'% row `agentrow' of `maxrownum'"
					
				}
				
					
			frame change results
			
				compress
			save RFSRX_LocalListings_AllAnalysis_02, replace
			
			frame change default
			frame drop agentnums
			frame drop results

		
		use RFSRX_AgentCompAnalysis_HoldFile, clear
		
			merge 1:1 ams_id list_date agent_uniquenum using RFSRX_LocalListings_AllAnalysis_02
				drop if _merge==2
				drop _merge		

		replace agentpastlisting_025 = 0 if agentpastlisting_025==.
		
		collapse (mean) ///
			agent_listcount_validloc_past ///
			agent_dist_avg_past ///
			agent_avg_lnsaletolist_past ///
			agentpastlisting_025 ///
			, by(ams_id list_date redx_agent2 geo_dist_past)

		merge m:1 ams_id using RFSRX_ListingPropertyInfo
			drop if _merge==2
			drop _merge
		

		gen listyear = year(list_date)
		gen listmonth = month(list_date)

		
		encode ams_state, gen(nstate)
			drop ams_state
		
		
		
		gen log_agent_disp_past = log(agent_dist_avg_past)
			drop agent_dist_avg_past

		gen log_agent_distance_past = log(geo_dist_past)
			drop geo_dist_past
		
		gen byte area_newagent_025 = 0 if agentpastlisting_025<.

		
		replace area_newagent_025 = 1 if agentpastlisting_025==0


			drop agentpastlisting_025 
		
		compress
	save RFSRX_AppendixFile_01, replace
	
	
	
	
	
	
	
	
	
	
	
	postfile outputcheck str3 table column str30 field str30 subfield double value double papervalue using "output\outputcheck.dta", replace
	
	use RFSRX_LeadsMain, clear
	
	*Table 2
	
		eststo clear

			eststo: reghdfe bedrooms iqip if num==1  & zillowmatched==1 & product<. & bedrooms>0, cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("2") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000385)
					post outputcheck ("2") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-0.13)
					post outputcheck ("2") (1) ("Observations") ("") (e(N)) (615482)
					post outputcheck ("2") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.129)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("2") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (3.04)
			
			eststo: reghdfe bathrooms iqip if num==1  & zillowmatched==1 & product<. & bathrooms>0, cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("2") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (-0.00268)
					post outputcheck ("2") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-0.97)
					post outputcheck ("2") (2) ("Observations") ("") (e(N)) (611773)
					post outputcheck ("2") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.200)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("2") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (2.35)
			
			eststo: reghdfe lsqft iqip if num==1  & zillowmatched==1 & product<. & lsqft<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("2") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00285)
					post outputcheck ("2") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.55)
					post outputcheck ("2") (3) ("Observations") ("") (e(N)) (596093)
					post outputcheck ("2") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.157)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("2") (3) ("Dependent Variable Average") ("") (round(r(mean),.01)) (5.13)
			
			eststo: reghdfe twogarage iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("2") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00193)
					post outputcheck ("2") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (0.64)
					post outputcheck ("2") (4) ("Observations") ("") (e(N)) (106403)
					post outputcheck ("2") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.055)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("2") (4) ("Dependent Variable Average") ("") (round(r(mean),.01)) (0.81)
					
			eststo: reghdfe logpredictedprice iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("2") (5) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000167)
					post outputcheck ("2") (5) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-0.03)
					post outputcheck ("2") (5) ("Observations") ("") (e(N)) (121484)
					post outputcheck ("2") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.385)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("2") (5) ("Dependent Variable Average") ("") (round(r(mean),.01)) (12.15)
			
		esttab using output\Table_02.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
	
	
	*Table 3
	
		eststo clear
 
			eststo: reghdfe lpagent_redx iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("3") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00597)
					post outputcheck ("3") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (4.23)
					post outputcheck ("3") (1) ("Observations") ("") (e(N)) (654991)
					post outputcheck ("3") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.172)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("3") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (0.20)

			eststo: reghdfe lpagent_noredx iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("3") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (-0.00221)
					post outputcheck ("3") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.95)
					post outputcheck ("3") (2) ("Observations") ("") (e(N)) (654991)
					post outputcheck ("3") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.143)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("3") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (0.13)
		 
			eststo: reghdfe lpagent iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("3") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00376)
					post outputcheck ("3") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (2.34)
					post outputcheck ("3") (3) ("Observations") ("") (e(N)) (654991)
					post outputcheck ("3") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.213)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("3") (3) ("Dependent Variable Average") ("") (round(r(mean),.01)) (0.33)

			eststo: reghdfe lpagent_win5days iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("3") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00232)
					post outputcheck ("3") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (3.49)
					post outputcheck ("3") (4) ("Observations") ("") (e(N)) (654991)
					post outputcheck ("3") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.013)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("3") (4) ("Dependent Variable Average") ("") (round(r(mean),.001)) (0.023)

			eststo: reghdfe lpagent_win3days iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("3") (5) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00213)
					post outputcheck ("3") (5) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (3.95)
					post outputcheck ("3") (5) ("Observations") ("") (e(N)) (654991)
					post outputcheck ("3") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.007)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("3") (5) ("Dependent Variable Average") ("") (round(r(mean),.001)) (0.015)
	 
		esttab using output\Table_03.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
	 
	 *Table 4
	 
		eststo clear
		 
			eststo: reghdfe ln_agentchar_leaddist_past iqip if num==1  & zillowmatched==1 & product<. & agent_multipleagents==0 & agent_farsmalllisting_daydiff>0, cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("4") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (0.0444)
					post outputcheck ("4") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (3.74)
					post outputcheck ("4") (1) ("Observations") ("") (e(N)) (127302)
					post outputcheck ("4") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.031)
		 
			eststo: reghdfe ln_agentchar_dispersion_past iqip if num==1  & zillowmatched==1 & product<. & agent_multipleagents==0 & agent_farsmalllisting_daydiff>0, cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("4") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (0.0427)
					post outputcheck ("4") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (3.07)
					post outputcheck ("4") (2) ("Observations") ("") (e(N)) (119429)
					post outputcheck ("4") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.026)
					
			eststo: reghdfe area_newagent_025 iqip if num==1  & zillowmatched==1 & product<. & agent_multipleagents==0 & agent_farsmalllisting_daydiff>0, cluster(county cw) absorb(cm#county totnew)	
					post outputcheck ("4") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00444)
					post outputcheck ("4") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.83)
					post outputcheck ("4") (3) ("Observations") ("") (e(N)) (125207)
					post outputcheck ("4") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.021)
					
			eststo: reghdfe agentchar_lnsaletolist_past iqip if num==1  & zillowmatched==1 & product<. & agent_multipleagents==0 & agent_farsmalllisting_daydiff>0, cluster(county cw) absorb(cm#county totnew)	
					post outputcheck ("4") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00514)
					post outputcheck ("4") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.95)
					post outputcheck ("4") (4) ("Observations") ("") (e(N)) (104259)
					post outputcheck ("4") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.164)
		
			eststo: ppmlhdfe agentchar_listcount_past iqip if num==1  & zillowmatched==1 & product<. & agent_multipleagents==0 & agent_farsmalllisting_daydiff>0, cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("4") (5) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (0.0342)
					post outputcheck ("4") (5) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.26)
					post outputcheck ("4") (5) ("Observations") ("") (e(N)) (134820)
					post outputcheck ("4") (5) ("Adj. R2") ("") (round(e(r2_p),.001)) (0.654)

		esttab using output\Table_04.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
				
	*Table 5
	
		eststo clear
		
			eststo: reghdfe somelistedagent iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("5") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (-0.00018)
					post outputcheck ("5") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-0.14)
					post outputcheck ("5") (1) ("Observations") ("") (e(N)) (654991)
					post outputcheck ("5") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.259)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("5") (1) ("Dependent Variable Average") ("") (round(r(mean),.001)) (0.164)
			
			eststo: reghdfe redxbuyeragent iqip if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("5") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (0.0013)
					post outputcheck ("5") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.72)
					post outputcheck ("5") (2) ("Observations") ("") (e(N)) (654991)
					post outputcheck ("5") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.095)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("5") (2) ("Dependent Variable Average") ("") (round(r(mean),.001)) (0.052)
				
			eststo: reghdfe redxbuyeragent iqip if num==1 & zillowmatched==1 & product<. & somelistedagent==1, cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("5") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (0.0110)
					post outputcheck ("5") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (2.21)
					post outputcheck ("5") (3) ("Observations") ("") (e(N)) (72787)
					post outputcheck ("5") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.111)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("5") (3) ("Dependent Variable Average") ("") (round(r(mean),.001)) (0.309)
					
			eststo: reghdfe redxbuyeragent iqip anysameagent if num==1 & zillowmatched==1 & product<. & somelistedagent==1, cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("5") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (0.0104)
					post outputcheck ("5") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.80)
					post outputcheck ("5") (4) ("Same Buyer and Listing Agent") ("Coefficient") (round(r(table)[1,2],.001)) (0.184)
					post outputcheck ("5") (4) ("Same Buyer and Listing Agent") ("t-stat") (round(r(table)[3,2],.01)) (15.300)
					post outputcheck ("5") (4) ("Observations") ("") (e(N)) (58908)
					post outputcheck ("5") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.119)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("5") (4) ("Dependent Variable Average") ("") (round(r(mean),.001)) (0.358)
							
		esttab using output\Table_05.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		
		
	*Table 6
	
		eststo clear
		
			eststo: reghdfe qs agent wrat if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("6") (1) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.0001)) (-0.0314)
					post outputcheck ("6") (1) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (-7.75)
					post outputcheck ("6") (1) ("Ratio of Trans to Lists") ("Coefficient") (round(r(table)[1,2],.00001)) (.0012)
					post outputcheck ("6") (1) ("Ratio of Trans to Lists") ("t-stat") (round(r(table)[3,2],.01)) (3.83)
					post outputcheck ("6") (1) ("Observations") ("") (e(N)) (392923)
					post outputcheck ("6") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.093)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("6") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (0.09)
			
			eststo: reghdfe salehazard365 agent wrat if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("6") (2) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.001)) (0.121)
					post outputcheck ("6") (2) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (21.14)
					post outputcheck ("6") (2) ("Ratio of Trans to Lists") ("Coefficient") (round(r(table)[1,2],.00001)) (.00322)
					post outputcheck ("6") (2) ("Ratio of Trans to Lists") ("t-stat") (round(r(table)[3,2],.01)) (4.78)
					post outputcheck ("6") (2) ("Observations") ("") (e(N)) (392923)
					post outputcheck ("6") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.324)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("6") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (0.38)
			
			eststo: reghdfe qs iqip wrat if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("6") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00218)
					post outputcheck ("6") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (2.19)
					post outputcheck ("6") (3) ("Ratio of Trans to Lists") ("Coefficient") (round(r(table)[1,2],.00001)) (.00155)
					post outputcheck ("6") (3) ("Ratio of Trans to Lists") ("t-stat") (round(r(table)[3,2],.01)) (4.86)
					post outputcheck ("6") (3) ("Observations") ("") (e(N)) (392923)
					post outputcheck ("6") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.091)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("6") (3) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.09)

			eststo: reghdfe salehazard365 iqip wrat if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("6") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00034)
					post outputcheck ("6") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (.21)
					post outputcheck ("6") (4) ("Ratio of Trans to Lists") ("Coefficient") (round(r(table)[1,2],.00001)) (.00187)
					post outputcheck ("6") (4) ("Ratio of Trans to Lists") ("t-stat") (round(r(table)[3,2],.01)) (2.78)
					post outputcheck ("6") (4) ("Observations") ("") (e(N)) (392923)
					post outputcheck ("6") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.312)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("6") (4) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.38)
				
			eststo: reghdfe salehazard iqip wrat if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("6") (5) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00232)
					post outputcheck ("6") (5) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.45)
					post outputcheck ("6") (5) ("Ratio of Trans to Lists") ("Coefficient") (round(r(table)[1,2],.000001)) (.000788)
					post outputcheck ("6") (5) ("Ratio of Trans to Lists") ("t-stat") (round(r(table)[3,2],.01)) (1.36)
					post outputcheck ("6") (5) ("Observations") ("") (e(N)) (392923)
					post outputcheck ("6") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (.282)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("6") (5) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.52)
				
			eststo: reghdfe longsale iqip wrat if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("6") (6) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00169)
					post outputcheck ("6") (6) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.96)
					post outputcheck ("6") (6) ("Ratio of Trans to Lists") ("Coefficient") (round(r(table)[1,2],.000001)) (.000025)
					post outputcheck ("6") (6) ("Ratio of Trans to Lists") ("t-stat") (round(r(table)[3,2],.01)) (.07)
					post outputcheck ("6") (6) ("Observations") ("") (e(N)) (392923)
					post outputcheck ("6") (6) ("Adj. R2") ("") (round(e(r2_a),.001)) (.023)
						local depvar = e(depvar)
						su `depvar' if e(sample)
					post outputcheck ("6") (6) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.05)
			 
		esttab using output\Table_06.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		
	*Table 7
	
		eststo clear
		 
			eststo: reghdfe mainpricevar agent pricecontrol if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
				*gen sample_sales = 1 if e(sample)
						post outputcheck ("7") (1) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.0001)) (.0264)
						post outputcheck ("7") (1) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (6.38)
						post outputcheck ("7") (1) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.179)
						post outputcheck ("7") (1) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (14.61)
						post outputcheck ("7") (1) ("Observations") ("") (e(N)) (82408)
						post outputcheck ("7") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.063)
							local depvar = e(depvar)
							su `depvar' if e(sample)
						post outputcheck ("7") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.09)
			  
			eststo: reghdfe mainpricevar iqip pricecontrol if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("7") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00647)
						post outputcheck ("7") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.88)
						post outputcheck ("7") (2) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.179)
						post outputcheck ("7") (2) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (14.62)
						post outputcheck ("7") (2) ("Observations") ("") (e(N)) (82408)
						post outputcheck ("7") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.063)
							local depvar = e(depvar)
							su `depvar' if e(sample)
						post outputcheck ("7") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.09)
				
			eststo: reghdfe logsales iqip pricecontrol logpredictedprice if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew) 
						post outputcheck ("7") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00761)
						post outputcheck ("7") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.81)
						post outputcheck ("7") (3) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.201)
						post outputcheck ("7") (3) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (15.69)
						post outputcheck ("7") (3) ("Log Predicted Sales Price") ("Coefficient") (round(r(table)[1,3],.001)) (.844)
						post outputcheck ("7") (3) ("Log Predicted Sales Price") ("t-stat") (round(r(table)[3,3],.01)) (110.33)
						post outputcheck ("7") (3) ("Observations") ("") (e(N)) (79117)
						post outputcheck ("7") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.719)
							local depvar = e(depvar)
							su `depvar' if e(sample)
						post outputcheck ("7") (3) ("Dependent Variable Average") ("") (round(r(mean),.01)) (12.26)
			
		esttab using output\Table_07.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
	
	*Table 8
		eststo clear

			eststo: reghdfe mainpricevar agent pricecontrol if num==1  & zillowmatched==1 & product<. & thickmarket==1, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8A") (1) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.0001)) (.0236)
						post outputcheck ("8A") (1) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (3.32)
						post outputcheck ("8A") (1) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (0.191)
						post outputcheck ("8A") (1) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (8.41)
						post outputcheck ("8A") (1) ("Observations") ("") (e(N)) (27710)
						post outputcheck ("8A") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.006)
				
			eststo: reghdfe mainpricevar agent pricecontrol if num==1  & zillowmatched==1 & product<. & thickmarket==0, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8A") (2) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.0001)) (.0303)
						post outputcheck ("8A") (2) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (4.14)
						post outputcheck ("8A") (2) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.178)
						post outputcheck ("8A") (2) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (10.31)
						post outputcheck ("8A") (2) ("Observations") ("") (e(N)) (26429)
						post outputcheck ("8A") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (0)
				
			eststo: reghdfe mainpricevar agent pricecontrol if num==1  & zillowmatched==1 & product<. & thickbeds==1, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8A") (3) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.0001)) (.03400)
						post outputcheck ("8A") (3) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (3.01)
						post outputcheck ("8A") (3) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.15)
						post outputcheck ("8A") (3) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (5.02)
						post outputcheck ("8A") (3) ("Observations") ("") (e(N)) (8800)
						post outputcheck ("8A") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.089)
				
			eststo: reghdfe mainpricevar agent pricecontrol if num==1  & zillowmatched==1 & product<. & thickbeds==0, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8A") (4) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.0001)) (.0249)
						post outputcheck ("8A") (4) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (4.91)
						post outputcheck ("8A") (4) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (0.184)
						post outputcheck ("8A") (4) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (13.87)
						post outputcheck ("8A") (4) ("Observations") ("") (e(N)) (52206)
						post outputcheck ("8A") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.069)
				
			eststo: reghdfe mainpricevar agent pricecontrol if num==1  & zillowmatched==1 & product<. & thicksqft==1, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8A") (5) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.0001)) (.0266)
						post outputcheck ("8A") (5) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (3.62)
						post outputcheck ("8A") (5) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.135)
						post outputcheck ("8A") (5) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (10.47)
						post outputcheck ("8A") (5) ("Observations") ("") (e(N)) (24028)
						post outputcheck ("8A") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.028)
				
			eststo: reghdfe mainpricevar agent pricecontrol if num==1  & zillowmatched==1 & product<. & thicksqft==0, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8A") (6) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.0001)) (.0292)
						post outputcheck ("8A") (6) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (2.84)
						post outputcheck ("8A") (6) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.15)
						post outputcheck ("8A") (6) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (8.32)
						post outputcheck ("8A") (6) ("Observations") ("") (e(N)) (18328)
						post outputcheck ("8A") (6) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.043)
				
		esttab using output\Table_08A.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
				
		eststo clear

			eststo: reghdfe mainpricevar iqip pricecontrol if num==1  & zillowmatched==1 & product<. & thickmarket==1, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8B") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (.0123)
						post outputcheck ("8B") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (2.75)
						post outputcheck ("8B") (1) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.191)
						post outputcheck ("8B") (1) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (8.42)
						post outputcheck ("8B") (1) ("Observations") ("") (e(N)) (27710)
						post outputcheck ("8B") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.007)
				
			eststo: reghdfe mainpricevar iqip pricecontrol if num==1  & zillowmatched==1 & product<. & thickmarket==0, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8B") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00079)
						post outputcheck ("8B") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (.11)
						post outputcheck ("8B") (2) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.178)
						post outputcheck ("8B") (2) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (10.35)
						post outputcheck ("8B") (2) ("Observations") ("") (e(N)) (26429)
						post outputcheck ("8B") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.001)
				
			eststo: reghdfe mainpricevar iqip pricecontrol if num==1  & zillowmatched==1 & product<. & thickbeds==1, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8B") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (.0313)
						post outputcheck ("8B") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (3.04)
						post outputcheck ("8B") (3) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.151)
						post outputcheck ("8B") (3) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (5.07)
						post outputcheck ("8B") (3) ("Observations") ("") (e(N)) (8800)
						post outputcheck ("8B") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.089)
				
			eststo: reghdfe mainpricevar iqip pricecontrol if num==1  & zillowmatched==1 & product<. & thickbeds==0, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8B") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00579)
						post outputcheck ("8B") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.55)
						post outputcheck ("8B") (4) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.185)
						post outputcheck ("8B") (4) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (13.88)
						post outputcheck ("8B") (4) ("Observations") ("") (e(N)) (52206)
						post outputcheck ("8B") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.069)
				
			eststo: reghdfe mainpricevar iqip pricecontrol if num==1  & zillowmatched==1 & product<. & thicksqft==1, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8B") (5) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00339)
						post outputcheck ("8B") (5) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (0.61)
						post outputcheck ("8B") (5) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.135)
						post outputcheck ("8B") (5) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (10.5)
						post outputcheck ("8B") (5) ("Observations") ("") (e(N)) (24028)
						post outputcheck ("8B") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.029)
				
			eststo: reghdfe mainpricevar iqip pricecontrol if num==1  & zillowmatched==1 & product<. & thicksqft==0, cluster(county cw) absorb(cm#county totnew)
						post outputcheck ("8B") (6) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00946)
						post outputcheck ("8B") (6) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.20)
						post outputcheck ("8B") (6) ("Avg Historical Resids") ("Coefficient") (round(r(table)[1,2],.001)) (.15)
						post outputcheck ("8B") (6) ("Avg Historical Resids") ("t-stat") (round(r(table)[3,2],.01)) (8.32)
						post outputcheck ("8B") (6) ("Observations") ("") (e(N)) (18328)
						post outputcheck ("8B") (6) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.044)
				
		esttab using output\Table_08B.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		
	*Table 9
		
		eststo clear
		
			eststo: reghdfe ratlist_30 agent if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9A") (1) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00110)
				post outputcheck ("9A") (1) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (3.69)
				post outputcheck ("9A") (1) ("Observations") ("") (e(N)) (500749)
				post outputcheck ("9A") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.372)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9A") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
				
			eststo: reghdfe ratlist_60 agent if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9A") (2) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.000001)) (0.000926)
				post outputcheck ("9A") (2) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (3.96)
				post outputcheck ("9A") (2) ("Observations") ("") (e(N)) (513936)
				post outputcheck ("9A") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.453)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9A") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_90 agent if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9A") (3) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.000001)) (0.000928)
				post outputcheck ("9A") (3) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (4.57)
				post outputcheck ("9A") (3) ("Observations") ("") (e(N)) (519533)
				post outputcheck ("9A") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.501)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9A") (3) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_120 agent if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9A") (4) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00101)
				post outputcheck ("9A") (4) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (5)
				post outputcheck ("9A") (4) ("Observations") ("") (e(N)) (522638)
				post outputcheck ("9A") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.536)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9A") (4) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_150 agent if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9A") (5) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00105)
				post outputcheck ("9A") (5) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (5.39)
				post outputcheck ("9A") (5) ("Observations") ("") (e(N)) (524738)
				post outputcheck ("9A") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (.559)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9A") (5) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_180 agent if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9A") (6) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00102)
				post outputcheck ("9A") (6) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (5.74)
				post outputcheck ("9A") (6) ("Observations") ("") (e(N)) (526121)
				post outputcheck ("9A") (6) ("Adj. R2") ("") (round(e(r2_a),.001)) (.579)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9A") (6) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_270 agent if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9A") (7) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00109)
				post outputcheck ("9A") (7) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (6.91)
				post outputcheck ("9A") (7) ("Observations") ("") (e(N)) (528582)
				post outputcheck ("9A") (7) ("Adj. R2") ("") (round(e(r2_a),.001)) (.62)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9A") (7) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_365 agent if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9A") (8) ("Agent Hired") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00117)
				post outputcheck ("9A") (8) ("Agent Hired") ("t-stat") (round(r(table)[3,1],.01)) (8.13)
				post outputcheck ("9A") (8) ("Observations") ("") (e(N)) (529831)
				post outputcheck ("9A") (8) ("Adj. R2") ("") (round(e(r2_a),.001)) (.647)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9A") (8) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
						
		esttab using output\Table_09A.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		
		eststo clear
		
			eststo: reghdfe ratlist_30 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9B") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000442)
				post outputcheck ("9B") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.56)
				post outputcheck ("9B") (1) ("Observations") ("") (e(N)) (500749)
				post outputcheck ("9B") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.372)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9B") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
				
			eststo: reghdfe ratlist_60 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9B") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000646)
				post outputcheck ("9B") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-3.03)
				post outputcheck ("9B") (2) ("Observations") ("") (e(N)) (513936)
				post outputcheck ("9B") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.453)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9B") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_90 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9B") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000407)
				post outputcheck ("9B") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-2.06)
				post outputcheck ("9B") (3) ("Observations") ("") (e(N)) (519533)
				post outputcheck ("9B") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.501)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9B") (3) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_120 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9B") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000267)
				post outputcheck ("9B") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.58)
				post outputcheck ("9B") (4) ("Observations") ("") (e(N)) (522638)
				post outputcheck ("9B") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.536)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9B") (4) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_150 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9B") (5) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000215)
				post outputcheck ("9B") (5) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.38)
				post outputcheck ("9B") (5) ("Observations") ("") (e(N)) (524738)
				post outputcheck ("9B") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (.559)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9B") (5) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_180 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9B") (6) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000186)
				post outputcheck ("9B") (6) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.21)
				post outputcheck ("9B") (6) ("Observations") ("") (e(N)) (526121)
				post outputcheck ("9B") (6) ("Adj. R2") ("") (round(e(r2_a),.001)) (.579)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9B") (6) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_270 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9B") (7) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000106)
				post outputcheck ("9B") (7) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-.78)
				post outputcheck ("9B") (7) ("Observations") ("") (e(N)) (528582)
				post outputcheck ("9B") (7) ("Adj. R2") ("") (round(e(r2_a),.001)) (.620)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9B") (7) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe ratlist_365 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("9B") (8) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000104)
				post outputcheck ("9B") (8) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-.78)
				post outputcheck ("9B") (8) ("Observations") ("") (e(N)) (529831)
				post outputcheck ("9B") (8) ("Adj. R2") ("") (round(e(r2_a),.001)) (.647)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("9B") (8) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
						
		esttab using output\Table_09B.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		
	*Table 10
		
		eststo clear
		
			eststo: reghdfe rattran_30 qs if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10A") (1) ("Quick Sale") ("Coefficient") (round(r(table)[1,1],.000001)) (0.000674)
				post outputcheck ("10A") (1) ("Quick Sale") ("t-stat") (round(r(table)[3,1],.01)) (2.2)
				post outputcheck ("10A") (1) ("Observations") ("") (e(N)) (529536)
				post outputcheck ("10A") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.473)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10A") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
				
			eststo: reghdfe rattran_60 qs if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10A") (2) ("Quick Sale") ("Coefficient") (round(r(table)[1,1],.000001)) (0.000726)
				post outputcheck ("10A") (2) ("Quick Sale") ("t-stat") (round(r(table)[3,1],.01)) (2.9)
				post outputcheck ("10A") (2) ("Observations") ("") (e(N)) (532547)
				post outputcheck ("10A") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.582)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10A") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_90 qs if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10A") (3) ("Quick Sale") ("Coefficient") (round(r(table)[1,1],.000001)) (0.000626)
				post outputcheck ("10A") (3) ("Quick Sale") ("t-stat") (round(r(table)[3,1],.01)) (2.72)
				post outputcheck ("10A") (3) ("Observations") ("") (e(N)) (533461)
				post outputcheck ("10A") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.637)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10A") (3) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_120 qs if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10A") (4) ("Quick Sale") ("Coefficient") (round(r(table)[1,1],.000001)) (0.000595)
				post outputcheck ("10A") (4) ("Quick Sale") ("t-stat") (round(r(table)[3,1],.01)) (2.82)
				post outputcheck ("10A") (4) ("Observations") ("") (e(N)) (533831)
				post outputcheck ("10A") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.671)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10A") (4) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_150 qs if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10A") (5) ("Quick Sale") ("Coefficient") (round(r(table)[1,1],.000001)) (0.000570)
				post outputcheck ("10A") (5) ("Quick Sale") ("t-stat") (round(r(table)[3,1],.01)) (2.87)
				post outputcheck ("10A") (5) ("Observations") ("") (e(N)) (534011)
				post outputcheck ("10A") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (.692)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10A") (5) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_180 qs if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10A") (6) ("Quick Sale") ("Coefficient") (round(r(table)[1,1],.000001)) (0.000574)
				post outputcheck ("10A") (6) ("Quick Sale") ("t-stat") (round(r(table)[3,1],.01)) (2.93)
				post outputcheck ("10A") (6) ("Observations") ("") (e(N)) (534117)
				post outputcheck ("10A") (6) ("Adj. R2") ("") (round(e(r2_a),.001)) (.705)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10A") (6) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_270 qs if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10A") (7) ("Quick Sale") ("Coefficient") (round(r(table)[1,1],.000001)) (0.000429)
				post outputcheck ("10A") (7) ("Quick Sale") ("t-stat") (round(r(table)[3,1],.01)) (2.31)
				post outputcheck ("10A") (7) ("Observations") ("") (e(N)) (534294)
				post outputcheck ("10A") (7) ("Adj. R2") ("") (round(e(r2_a),.001)) (.726)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10A") (7) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_365 qs if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10A") (8) ("Quick Sale") ("Coefficient") (round(r(table)[1,1],.000001)) (0.000444)
				post outputcheck ("10A") (8) ("Quick Sale") ("t-stat") (round(r(table)[3,1],.01)) (2.44)
				post outputcheck ("10A") (8) ("Observations") ("") (e(N)) (534403)
				post outputcheck ("10A") (8) ("Adj. R2") ("") (round(e(r2_a),.001)) (.739)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10A") (8) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
						
		esttab using output\Table_10A.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		
		eststo clear
		
			eststo: reghdfe rattran_30 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10B") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00000001)) (0.00000772)
				post outputcheck ("10B") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (.04)
				post outputcheck ("10B") (1) ("Observations") ("") (e(N)) (529536)
				post outputcheck ("10B") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.473)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10B") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
				
			eststo: reghdfe rattran_60 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10B") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000154)
				post outputcheck ("10B") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.09)
				post outputcheck ("10B") (2) ("Observations") ("") (e(N)) (532547)
				post outputcheck ("10B") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.582)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10B") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_90 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10B") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000218)
				post outputcheck ("10B") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.71)
				post outputcheck ("10B") (3) ("Observations") ("") (e(N)) (533461)
				post outputcheck ("10B") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.637)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10B") (3) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_120 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10B") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000139)
				post outputcheck ("10B") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.03)
				post outputcheck ("10B") (4) ("Observations") ("") (e(N)) (533831)
				post outputcheck ("10B") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.671)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10B") (4) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_150 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10B") (5) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000169)
				post outputcheck ("10B") (5) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.46)
				post outputcheck ("10B") (5) ("Observations") ("") (e(N)) (534011)
				post outputcheck ("10B") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (.692)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10B") (5) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_180 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10B") (6) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000203)
				post outputcheck ("10B") (6) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.79)
				post outputcheck ("10B") (6) ("Observations") ("") (e(N)) (534117)
				post outputcheck ("10B") (6) ("Adj. R2") ("") (round(e(r2_a),.001)) (.705)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10B") (6) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_270 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10B") (7) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000279)
				post outputcheck ("10B") (7) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-2.49)
				post outputcheck ("10B") (7) ("Observations") ("") (e(N)) (534294)
				post outputcheck ("10B") (7) ("Adj. R2") ("") (round(e(r2_a),.001)) (.726)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10B") (7) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
			
			eststo: reghdfe rattran_365 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("10B") (8) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-0.000281)
				post outputcheck ("10B") (8) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-2.78)
				post outputcheck ("10B") (8) ("Observations") ("") (e(N)) (534403)
				post outputcheck ("10B") (8) ("Adj. R2") ("") (round(e(r2_a),.001)) (.739)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("10B") (8) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
						
		esttab using output\Table_10B.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		
	*Table 11
		
		eststo clear
			eststo: reghdfe lpagent_redx iqip c.iqip#c.brokcontrol brokcontrol if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
				post outputcheck ("11") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (0.0105)
				post outputcheck ("11") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (5.13)
				post outputcheck ("11") (1) ("Interaction") ("Coefficient") (round(r(table)[1,2],.00001)) (-0.00662)
				post outputcheck ("11") (1) ("Interaction") ("t-stat") (round(r(table)[3,2],.01)) (-2.51)
				post outputcheck ("11") (1) ("Hist Frac Agent Lists") ("Coefficient") (round(r(table)[1,3],.0001)) (0.0217)
				post outputcheck ("11") (1) ("Hist Frac Agent Lists") ("t-stat") (round(r(table)[3,3],.01)) (3.72)
				post outputcheck ("11") (1) ("Observations") ("") (e(N)) (495558)
				post outputcheck ("11") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.158)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("11") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.22)

			eststo: reghdfe lpagent_redx iqip c.iqip#c.lsqft lsqft if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
				post outputcheck ("11") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (0.0467)
				post outputcheck ("11") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (4.01)
				post outputcheck ("11") (2) ("Interaction") ("Coefficient") (round(r(table)[1,2],.00001)) (-0.00798)
				post outputcheck ("11") (2) ("Interaction") ("t-stat") (round(r(table)[3,2],.01)) (-3.55)
				post outputcheck ("11") (2) ("Log Square Feet") ("Coefficient") (round(r(table)[1,3],.0001)) (0.0601)
				post outputcheck ("11") (2) ("Log Square Feet") ("t-stat") (round(r(table)[3,3],.01)) (12.29)
				post outputcheck ("11") (2) ("Observations") ("") (e(N)) (596093)
				post outputcheck ("11") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.181)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("11") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.21)

			eststo: reghdfe lpagent_redx iqip c.iqip#c.bedrooms bedrooms if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
				post outputcheck ("11") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (0.0147)
				post outputcheck ("11") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (4.51)
				post outputcheck ("11") (3) ("Interaction") ("Coefficient") (round(r(table)[1,2],.00001)) (-0.00295)
				post outputcheck ("11") (3) ("Interaction") ("t-stat") (round(r(table)[3,2],.01)) (-2.98)
				post outputcheck ("11") (3) ("Bedrooms") ("Coefficient") (round(r(table)[1,3],.0001)) (0.0169)
				post outputcheck ("11") (3) ("Bedrooms") ("t-stat") (round(r(table)[3,3],.01)) (8.23)
				post outputcheck ("11") (3) ("Observations") ("") (e(N)) (654991)
				post outputcheck ("11") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.175)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("11") (3) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.20)

		esttab using output\Table_11.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
				
	*Table 1
		
		su frbo if sample_full==1, de
			post outputcheck ("1A") (.) ("FRBO") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("FRBO") ("Mean") (round(r(mean),.01)) (0.41)
			post outputcheck ("1A") (.) ("FRBO") ("Standard Deviation") (round(r(sd),.01)) (0.49)
		
		su bedrooms if sample_full==1 & bedrooms>0, de
			post outputcheck ("1A") (.) ("Bedrooms") ("Observations") (r(N)) (621204)
			post outputcheck ("1A") (.) ("Bedrooms") ("Mean") (round(r(mean),.01)) (3.04)
			post outputcheck ("1A") (.) ("Bedrooms") ("Standard Deviation") (round(r(sd),.01)) (0.82)
			post outputcheck ("1A") (.) ("Bedrooms") ("Q5") (r(p5)) (2)
			post outputcheck ("1A") (.) ("Bedrooms") ("Q25") (r(p25)) (3)
			post outputcheck ("1A") (.) ("Bedrooms") ("Q50") (r(p50)) (3)
			post outputcheck ("1A") (.) ("Bedrooms") ("Q75") (r(p75)) (4)
			post outputcheck ("1A") (.) ("Bedrooms") ("Q95") (r(p95)) (4)
			
		su bathrooms if sample_full==1 & bathrooms>0, de
			post outputcheck ("1A") (.) ("Bathrooms") ("Observations") (r(N)) (617742)
			post outputcheck ("1A") (.) ("Bathrooms") ("Mean") (round(r(mean),.01)) (2.34)
			post outputcheck ("1A") (.) ("Bathrooms") ("Standard Deviation") (round(r(sd),.01)) (0.73)
			post outputcheck ("1A") (.) ("Bathrooms") ("Q5") (r(p5)) (1)
			post outputcheck ("1A") (.) ("Bathrooms") ("Q25") (r(p25)) (2)
			post outputcheck ("1A") (.) ("Bathrooms") ("Q50") (r(p50)) (2)
			post outputcheck ("1A") (.) ("Bathrooms") ("Q75") (r(p75)) (3)
			post outputcheck ("1A") (.) ("Bathrooms") ("Q95") (r(p95)) (3)
			
		su sqftbuckets if sample_full==1 & lsqft<., de
			post outputcheck ("1A") (.) ("Sq Ft") ("Observations") (r(N)) (605822)
			post outputcheck ("1A") (.) ("Sq Ft") ("Mean") (round(r(mean)*10,1)) (1861)
			post outputcheck ("1A") (.) ("Sq Ft") ("Standard Deviation") (round(r(sd)*10,1)) (867)
			post outputcheck ("1A") (.) ("Sq Ft") ("Q5") (r(p5)*10) (800)
			post outputcheck ("1A") (.) ("Sq Ft") ("Q25") (r(p25)*10) (1200)
			post outputcheck ("1A") (.) ("Sq Ft") ("Q50") (r(p50)*10) (1700)
			post outputcheck ("1A") (.) ("Sq Ft") ("Q75") (r(p75)*10) (2300)
			post outputcheck ("1A") (.) ("Sq Ft") ("Q95") (r(p95)*10) (3600)
			
		su twogarage if sample_full==1, de
			post outputcheck ("1A") (.) ("Two-Car Garage") ("Observations") (r(N)) (157997)
			post outputcheck ("1A") (.) ("Two-Car Garage") ("Mean") (round(r(mean),.01)) (0.81)
			post outputcheck ("1A") (.) ("Two-Car Garage") ("Standard Deviation") (round(r(sd),.01)) (0.39)
		
		su createdate if sample_full==1, de
			post outputcheck ("1A") (.) ("Lead Create Date") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("Lead Create Date") ("Mean") (round(r(mean),1)) (20948)
			post outputcheck ("1A") (.) ("Lead Create Date") ("Standard Deviation") (round(r(sd),1)) (279)
			post outputcheck ("1A") (.) ("Lead Create Date") ("Q5") (r(p5)) (20517)
			post outputcheck ("1A") (.) ("Lead Create Date") ("Q25") (r(p25)) (20690)
			post outputcheck ("1A") (.) ("Lead Create Date") ("Q50") (r(p50)) (20955)
			post outputcheck ("1A") (.) ("Lead Create Date") ("Q75") (r(p75)) (21202)
			post outputcheck ("1A") (.) ("Lead Create Date") ("Q95") (r(p95)) (21363)
			
		su ziprank if sample_full==1, de
			post outputcheck ("1A") (.) ("Rank of Lead Number") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("Rank of Lead Number") ("Mean") (round(r(mean),.01)) (18.02)
			post outputcheck ("1A") (.) ("Rank of Lead Number") ("Standard Deviation") (round(r(sd),.01)) (23.49)
			post outputcheck ("1A") (.) ("Rank of Lead Number") ("Q5") (r(p5)) (2)
			post outputcheck ("1A") (.) ("Rank of Lead Number") ("Q25") (r(p25)) (5)
			post outputcheck ("1A") (.) ("Rank of Lead Number") ("Q50") (r(p50)) (11)
			post outputcheck ("1A") (.) ("Rank of Lead Number") ("Q75") (r(p75)) (22)
			post outputcheck ("1A") (.) ("Rank of Lead Number") ("Q95") (r(p95)) (61)
			
		su totnewsize if sample_full==1, de
			post outputcheck ("1A") (.) ("Batch Size") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("Batch Size") ("Mean") (round(r(mean),.01)) (12.68)
			post outputcheck ("1A") (.) ("Batch Size") ("Standard Deviation") (round(r(sd),.01)) (16.91)
			post outputcheck ("1A") (.) ("Batch Size") ("Q5") (r(p5)) (2)
			post outputcheck ("1A") (.) ("Batch Size") ("Q25") (r(p25)) (4)
			post outputcheck ("1A") (.) ("Batch Size") ("Q50") (r(p50)) (7)
			post outputcheck ("1A") (.) ("Batch Size") ("Q75") (r(p75)) (15)
			post outputcheck ("1A") (.) ("Batch Size") ("Q95") (r(p95)) (41)
			
		su iqip if sample_full==1, de
			post outputcheck ("1A") (.) ("Intermediary Attention") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("Intermediary Attention") ("Mean") (round(r(mean),.01)) (-2.11)
			post outputcheck ("1A") (.) ("Intermediary Attention") ("Standard Deviation") (round(r(sd),.01)) (1)
			post outputcheck ("1A") (.) ("Intermediary Attention") ("Q5") (round(r(p5),.01)) (-3.74)
			post outputcheck ("1A") (.) ("Intermediary Attention") ("Q25") (round(r(p25),.01)) (-2.81)
			post outputcheck ("1A") (.) ("Intermediary Attention") ("Q50") (round(r(p50),.01)) (-2.18)
			post outputcheck ("1A") (.) ("Intermediary Attention") ("Q75") (round(r(p75),.01)) (-1.46)
			post outputcheck ("1A") (.) ("Intermediary Attention") ("Q95") (round(r(p95),.01)) (-0.63)

		su lpagent if sample_full==1, de
			post outputcheck ("1A") (.) ("Hired Agent") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("Hired Agent") ("Mean") (round(r(mean),.01)) (0.33)
			post outputcheck ("1A") (.) ("Hired Agent") ("Standard Deviation") (round(r(sd),.01)) (0.47)
			
		su lpagent_redx if sample_full==1, de
			post outputcheck ("1A") (.) ("Hired Affiliated Agent") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("Hired Affiliated Agent") ("Mean") (round(r(mean),.01)) (0.20)
			post outputcheck ("1A") (.) ("Hired Affiliated Agent") ("Standard Deviation") (round(r(sd),.01)) (0.40)
			
		su lpagent_noredx if sample_full==1, de
			post outputcheck ("1A") (.) ("Hired Unaffiliated Agent") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("Hired Unaffiliated Agent") ("Mean") (round(r(mean),.01)) (0.13)
			post outputcheck ("1A") (.) ("Hired Unaffiliated Agent") ("Standard Deviation") (round(r(sd),.01)) (0.33)
			
		su lp_daysuntillist if sample_full==1, de
			post outputcheck ("1A") (.) ("Days Until Agent Hiring") ("Observations") (r(N)) (221178)
			post outputcheck ("1A") (.) ("Days Until Agent Hiring") ("Mean") (round(r(mean),.01)) (251.22)
			post outputcheck ("1A") (.) ("Days Until Agent Hiring") ("Standard Deviation") (round(r(sd),.01)) (333.02)
			post outputcheck ("1A") (.) ("Days Until Agent Hiring") ("Q5") (r(p5)) (4)
			post outputcheck ("1A") (.) ("Days Until Agent Hiring") ("Q25") (r(p25)) (23)
			post outputcheck ("1A") (.) ("Days Until Agent Hiring") ("Q50") (r(p50)) (77)
			post outputcheck ("1A") (.) ("Days Until Agent Hiring") ("Q75") (r(p75)) (387)
			post outputcheck ("1A") (.) ("Days Until Agent Hiring") ("Q95") (r(p95)) (1008)
		
		su salehazard if sample_full==1, de
			post outputcheck ("1A") (.) ("Ever Sold") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("Ever Sold") ("Mean") (round(r(mean),.01)) (0.55)
			post outputcheck ("1A") (.) ("Ever Sold") ("Standard Deviation") (round(r(sd),.01)) (0.50)
			
		su salehazard365 if sample_full==1, de
			post outputcheck ("1A") (.) ("Sold Within One Year") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("Sold Within One Year") ("Mean") (round(r(mean),.01)) (0.41)
			post outputcheck ("1A") (.) ("Sold Within One Year") ("Standard Deviation") (round(r(sd),.01)) (0.49)
		
		su qs if sample_full==1, de
			post outputcheck ("1A") (.) ("Quick Sale") ("Observations") (r(N)) (654991)
			post outputcheck ("1A") (.) ("Quick Sale") ("Mean") (round(r(mean),.01)) (0.10)
			post outputcheck ("1A") (.) ("Quick Sale") ("Standard Deviation") (round(r(sd),.01)) (0.29)
			
		
		su salesprice_1000s if sample_full==1, de
			post outputcheck ("1A") (.) ("Sales Price") ("Observations") (r(N)) (252126)
			post outputcheck ("1A") (.) ("Sales Price") ("Mean") (round(r(mean),.01)) (295.56)
			post outputcheck ("1A") (.) ("Sales Price") ("Standard Deviation") (round(r(sd),.01)) (261.49)
			post outputcheck ("1A") (.) ("Sales Price") ("Q5") (r(p5)) (60)
			post outputcheck ("1A") (.) ("Sales Price") ("Q25") (r(p25)) (155)
			post outputcheck ("1A") (.) ("Sales Price") ("Q50") (r(p50)) (239)
			post outputcheck ("1A") (.) ("Sales Price") ("Q75") (r(p75)) (360)
			post outputcheck ("1A") (.) ("Sales Price") ("Q95") (r(p95)) (695)
			
		su focal_resid_salesprice if sample_sales==1, de
			post outputcheck ("1A") (.) ("Sales Price Residual") ("Observations") (r(N)) (82408)
			post outputcheck ("1A") (.) ("Sales Price Residual") ("Mean") (round(r(mean),.01)) (0.09)
			post outputcheck ("1A") (.) ("Sales Price Residual") ("Standard Deviation") (round(r(sd),.01)) (0.42)
			post outputcheck ("1A") (.) ("Sales Price Residual") ("Q5") (round(r(p5),.01)) (-0.44)
			post outputcheck ("1A") (.) ("Sales Price Residual") ("Q25") (round(r(p25),.01)) (-0.07)
			post outputcheck ("1A") (.) ("Sales Price Residual") ("Q50") (round(r(p50),.01)) (0.06)
			post outputcheck ("1A") (.) ("Sales Price Residual") ("Q75") (round(r(p75),.01)) (0.25)
			post outputcheck ("1A") (.) ("Sales Price Residual") ("Q95") (round(r(p95),.01)) (0.75)
				
		
		eststo clear

			eststo: reghdfe lpagent_redx topquartile if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
				post outputcheck ("A3") (1) ("Top Quartile Relative Rank") ("Coefficient") (round(r(table)[1,1],.00001)) (.00627)
				post outputcheck ("A3") (1) ("Top Quartile Relative Rank") ("t-stat") (round(r(table)[3,1],.01)) (3.61)
				post outputcheck ("A3") (1) ("Observations") ("") (e(N)) (654991)
				post outputcheck ("A3") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.172)
			
			eststo: reghdfe qs topquartile wrat if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
				post outputcheck ("A3") (2) ("Top Quartile Relative Rank") ("Coefficient") (round(r(table)[1,1],.00001)) (.00410)
				post outputcheck ("A3") (2) ("Top Quartile Relative Rank") ("t-stat") (round(r(table)[3,1],.01)) (2.77)
				post outputcheck ("A3") (2) ("Ratio Hist Tran to List") ("Coefficient") (round(r(table)[1,2],.00001)) (.00155)
				post outputcheck ("A3") (2) ("Ratio Hist Tran to List") ("t-stat") (round(r(table)[3,2],.01)) (4.76)
				post outputcheck ("A3") (2) ("Observations") ("") (e(N)) (392923)
				post outputcheck ("A3") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.091)
			
			eststo: reghdfe mainpricevar topquartile pricecontrol if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
				post outputcheck ("A3") (3) ("Top Quartile Relative Rank") ("Coefficient") (round(r(table)[1,1],.0001)) (.0108)
				post outputcheck ("A3") (3) ("Top Quartile Relative Rank") ("t-stat") (round(r(table)[3,1],.01)) (2.38)
				post outputcheck ("A3") (3) ("Avg Hist Sales Price") ("Coefficient") (round(r(table)[1,2],.001)) (.179)
				post outputcheck ("A3") (3) ("Avg Hist Sales Price") ("t-stat") (round(r(table)[3,2],.01)) (14.62)
				post outputcheck ("A3") (3) ("Observations") ("") (e(N)) (82408)
				post outputcheck ("A3") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.063)
			
			eststo: reghdfe ratlist_60 topquartile if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A3") (4) ("Top Quartile Relative Rank") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000868)
				post outputcheck ("A3") (4) ("Top Quartile Relative Rank") ("t-stat") (round(r(table)[3,1],.01)) (-2.65)
				post outputcheck ("A3") (4) ("Observations") ("") (e(N)) (513936)
				post outputcheck ("A3") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.453)
			
			eststo: reghdfe rattran_365 topquartile if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A3") (5) ("Top Quartile Relative Rank") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000309)
				post outputcheck ("A3") (5) ("Top Quartile Relative Rank") ("t-stat") (round(r(table)[3,1],.01)) (-1.96)
				post outputcheck ("A3") (5) ("Observations") ("") (e(N)) (534403)
				post outputcheck ("A3") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (.739)
		 
		esttab using output\Table_A3.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		 
		eststo clear

			eststo: reghdfe lpagent_redx i.rankquartiles if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
				post outputcheck ("A4") (1) ("Second Quartile") ("Coefficient") (round(r(table)[1,2],.00001)) (-.00497)
				post outputcheck ("A4") (1) ("Second Quartile") ("t-stat") (round(r(table)[3,2],.01)) (-2.87)
				post outputcheck ("A4") (1) ("Third Quartile") ("Coefficient") (round(r(table)[1,3],.00001)) (-.00796)
				post outputcheck ("A4") (1) ("Third Quartile") ("t-stat") (round(r(table)[3,3],.01)) (-3.49)
				post outputcheck ("A4") (1) ("Fourth Quartile") ("Coefficient") (round(r(table)[1,4],.0001)) (-.0117)
				post outputcheck ("A4") (1) ("Fourth Quartile") ("t-stat") (round(r(table)[3,4],.01)) (-4.72)
				post outputcheck ("A4") (1) ("Observations") ("") (e(N)) (654991)
				post outputcheck ("A4") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.172)
			
			eststo: reghdfe qs i.rankquartiles wrat if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
				post outputcheck ("A4") (2) ("Second Quartile") ("Coefficient") (round(r(table)[1,2],.00001)) (-.00427)
				post outputcheck ("A4") (2) ("Second Quartile") ("t-stat") (round(r(table)[3,2],.01)) (-2.77)
				post outputcheck ("A4") (2) ("Third Quartile") ("Coefficient") (round(r(table)[1,3],.00001)) (-.00506)
				post outputcheck ("A4") (2) ("Third Quartile") ("t-stat") (round(r(table)[3,3],.01)) (-2.66)
				post outputcheck ("A4") (2) ("Fourth Quartile") ("Coefficient") (round(r(table)[1,4],.000001)) (-.000839)
				post outputcheck ("A4") (2) ("Fourth Quartile") ("t-stat") (round(r(table)[3,4],.01)) (-.39)
				post outputcheck ("A4") (2) ("Ratio Hist Tran to List") ("Coefficient") (round(r(table)[1,5],.00001)) (.00155)
				post outputcheck ("A4") (2) ("Ratio Hist Tran to List") ("t-stat") (round(r(table)[3,5],.01)) (4.80)
				post outputcheck ("A4") (2) ("Observations") ("") (e(N)) (392923)
				post outputcheck ("A4") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.091)
			
			eststo: reghdfe mainpricevar i.rankquartiles pricecontrol if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
				post outputcheck ("A4") (3) ("Second Quartile") ("Coefficient") (round(r(table)[1,2],.0001)) (-.0104)
				post outputcheck ("A4") (3) ("Second Quartile") ("t-stat") (round(r(table)[3,2],.01)) (-2.24)
				post outputcheck ("A4") (3) ("Third Quartile") ("Coefficient") (round(r(table)[1,3],.00001)) (-.00617)
				post outputcheck ("A4") (3) ("Third Quartile") ("t-stat") (round(r(table)[3,3],.01)) (-1.05)
				post outputcheck ("A4") (3) ("Fourth Quartile") ("Coefficient") (round(r(table)[1,4],.0001)) (-.0221)
				post outputcheck ("A4") (3) ("Fourth Quartile") ("t-stat") (round(r(table)[3,4],.01)) (-2.96)
				post outputcheck ("A4") (3) ("Avg Hist Sales Price") ("Coefficient") (round(r(table)[1,5],.001)) (.179)
				post outputcheck ("A4") (3) ("Avg Hist Sales Price") ("t-stat") (round(r(table)[3,5],.01)) (14.61)
				post outputcheck ("A4") (3) ("Observations") ("") (e(N)) (82408)
				post outputcheck ("A4") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.063)
			
			eststo: reghdfe ratlist_60 i.rankquartiles if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A4") (4) ("Second Quartile") ("Coefficient") (round(r(table)[1,2],.000001)) (.000814)
				post outputcheck ("A4") (4) ("Second Quartile") ("t-stat") (round(r(table)[3,2],.01)) (2.47)
				post outputcheck ("A4") (4) ("Third Quartile") ("Coefficient") (round(r(table)[1,3],.000001)) (.000948)
				post outputcheck ("A4") (4) ("Third Quartile") ("t-stat") (round(r(table)[3,3],.01)) (2.4)
				post outputcheck ("A4") (4) ("Fourth Quartile") ("Coefficient") (round(r(table)[1,4],.00001)) (.00106)
				post outputcheck ("A4") (4) ("Fourth Quartile") ("t-stat") (round(r(table)[3,4],.01)) (2.05)
				post outputcheck ("A4") (4) ("Observations") ("") (e(N)) (513936)
				post outputcheck ("A4") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.452)
			
			eststo: reghdfe rattran_365 i.rankquartiles if num==1 & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A4") (5) ("Second Quartile") ("Coefficient") (round(r(table)[1,2],.000001)) (.000333)
				post outputcheck ("A4") (5) ("Second Quartile") ("t-stat") (round(r(table)[3,2],.01)) (2.01)
				post outputcheck ("A4") (5) ("Third Quartile") ("Coefficient") (round(r(table)[1,3],.000001)) (.000244)
				post outputcheck ("A4") (5) ("Third Quartile") ("t-stat") (round(r(table)[3,3],.01)) (1.28)
				post outputcheck ("A4") (5) ("Fourth Quartile") ("Coefficient") (round(r(table)[1,4],.000001)) (.000290)
				post outputcheck ("A4") (5) ("Fourth Quartile") ("t-stat") (round(r(table)[3,4],.01)) (1.42)
				post outputcheck ("A4") (5) ("Observations") ("") (e(N)) (534403)
				post outputcheck ("A4") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (.739)
		 
		esttab using output\Table_A4.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		
		eststo clear

			eststo: reghdfe qs c.iqip##i.vacantland wrat if num==1  & zillowmatched==1 & product==2, cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A5") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00407)
				post outputcheck ("A5") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (2.02)
				post outputcheck ("A5") (1) ("Vacant Land") ("Coefficient") (round(r(table)[1,3],.0001)) (-.0509)
				post outputcheck ("A5") (1) ("Vacant Land") ("t-stat") (round(r(table)[3,3],.01)) (-4.21)
				post outputcheck ("A5") (1) ("Interaction") ("Coefficient") (round(r(table)[1,5],.00001)) (-.00309)
				post outputcheck ("A5") (1) ("Interaction") ("t-stat") (round(r(table)[3,5],.01)) (-0.59)
				post outputcheck ("A5") (1) ("Hist Tran to List") ("Coefficient") (round(r(table)[1,6],.00001)) (.00242)
				post outputcheck ("A5") (1) ("Hist Tran to List") ("t-stat") (round(r(table)[3,6],.01)) (2.86)
				post outputcheck ("A5") (1) ("Observations") ("") (e(N)) (192941)
				post outputcheck ("A5") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.046)
		
			eststo: reghdfe qs c.iqip##i.onebedroom wrat if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A5") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.0017)
				post outputcheck ("A5") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.71)
				post outputcheck ("A5") (2) ("One Bedroom") ("Coefficient") (round(r(table)[1,3],.000001)) (.000251)
				post outputcheck ("A5") (2) ("One Bedroom") ("t-stat") (round(r(table)[3,3],.01)) (.04)
				post outputcheck ("A5") (2) ("Interaction") ("Coefficient") (round(r(table)[1,5],.000001)) (-.000597)
				post outputcheck ("A5") (2) ("Interaction") ("t-stat") (round(r(table)[3,5],.01)) (-.34)
				post outputcheck ("A5") (2) ("Hist Tran to List") ("Coefficient") (round(r(table)[1,6],.000001)) (-.000120)
				post outputcheck ("A5") (2) ("Hist Tran to List") ("t-stat") (round(r(table)[3,6],.01)) (-.24)
				post outputcheck ("A5") (2) ("Observations") ("") (e(N)) (368995)
				post outputcheck ("A5") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.093)

			eststo: reghdfe mainpricevar c.iqip##i.vacantland pricecontrol if num==1  & zillowmatched==1 & product==2, cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A5") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00681)
				post outputcheck ("A5") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.67)
				post outputcheck ("A5") (3) ("Vacant Land") ("Coefficient") (round(r(table)[1,3],.001)) (-.24)
				post outputcheck ("A5") (3) ("Vacant Land") ("t-stat") (round(r(table)[3,3],.01)) (-4.39)
				post outputcheck ("A5") (3) ("Interaction") ("Coefficient") (round(r(table)[1,5],.00001)) (.00917)
				post outputcheck ("A5") (3) ("Interaction") ("t-stat") (round(r(table)[3,5],.01)) (.42)
				post outputcheck ("A5") (3) ("Avg Hist Sales Price") ("Coefficient") (round(r(table)[1,6],.001)) (.174)
				post outputcheck ("A5") (3) ("Avg Hist Sales Price") ("t-stat") (round(r(table)[3,6],.01)) (12.45)
				post outputcheck ("A5") (3) ("Observations") ("") (e(N)) (58895)
				post outputcheck ("A5") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.057)
			
			eststo: reghdfe mainpricevar c.iqip##i.onebedroom pricecontrol if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A5") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (.00586)
				post outputcheck ("A5") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.64)
				post outputcheck ("A5") (4) ("One Bedroom") ("Coefficient") (round(r(table)[1,3],.001)) (-.125)
				post outputcheck ("A5") (4) ("One Bedroom") ("t-stat") (round(r(table)[3,3],.01)) (-3.35)
				post outputcheck ("A5") (4) ("Interaction") ("Coefficient") (round(r(table)[1,5],.0001)) (-.0141)
				post outputcheck ("A5") (4) ("Interaction") ("t-stat") (round(r(table)[3,5],.01)) (-1.04)
				post outputcheck ("A5") (4) ("Avg Hist Sales Price") ("Coefficient") (round(r(table)[1,6],.001)) (.178)
				post outputcheck ("A5") (4) ("Avg Hist Sales Price") ("t-stat") (round(r(table)[3,6],.01)) (12.78)
				post outputcheck ("A5") (4) ("Observations") ("") (e(N)) (65741)
				post outputcheck ("A5") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.06)
			
			eststo: reghdfe ratlist_60 c.iqip##i.vacantland if num==1  & zillowmatched==1 & product==2, cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A5") (5) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (-.00122)
				post outputcheck ("A5") (5) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-3.70)
				post outputcheck ("A5") (5) ("Vacant Land") ("Coefficient") (round(r(table)[1,3],.00001)) (-.00116)
				post outputcheck ("A5") (5) ("Vacant Land") ("t-stat") (round(r(table)[3,3],.01)) (-.61)
				post outputcheck ("A5") (5) ("Interaction") ("Coefficient") (round(r(table)[1,5],.000001)) (.000685)
				post outputcheck ("A5") (5) ("Interaction") ("t-stat") (round(r(table)[3,5],.01)) (0.97)
				post outputcheck ("A5") (5) ("Observations") ("") (e(N)) (282308)
				post outputcheck ("A5") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (.364)

			eststo: reghdfe ratlist_60 c.iqip##i.onebedroom if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A5") (6) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-.00061)
				post outputcheck ("A5") (6) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-2.8)
				post outputcheck ("A5") (6) ("One Bedroom") ("Coefficient") (round(r(table)[1,3],.00001)) (.00455)
				post outputcheck ("A5") (6) ("One Bedroom") ("t-stat") (round(r(table)[3,3],.01)) (3.23)
				post outputcheck ("A5") (6) ("Interaction") ("Coefficient") (round(r(table)[1,5],.000001)) (.000409)
				post outputcheck ("A5") (6) ("Interaction") ("t-stat") (round(r(table)[3,5],.01)) (.81)
				post outputcheck ("A5") (6) ("Observations") ("") (e(N)) (483190)
				post outputcheck ("A5") (6) ("Adj. R2") ("") (round(e(r2_a),.001)) (.447)
			
			eststo: reghdfe rattran_365 c.iqip##i.vacantland if num==1  & zillowmatched==1 & product==2, cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A5") (7) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000421)
				post outputcheck ("A5") (7) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-2.54)
				post outputcheck ("A5") (7) ("Vacant Land") ("Coefficient") (round(r(table)[1,3],.00001)) (-.00283)
				post outputcheck ("A5") (7) ("Vacant Land") ("t-stat") (round(r(table)[3,3],.01)) (-2.89)
				post outputcheck ("A5") (7) ("Interaction") ("Coefficient") (round(r(table)[1,5],.000001)) (-.000250)
				post outputcheck ("A5") (7) ("Interaction") ("t-stat") (round(r(table)[3,5],.01)) (-.7)
				post outputcheck ("A5") (7) ("Observations") ("") (e(N)) (297841)
				post outputcheck ("A5") (7) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.674)

			eststo: reghdfe rattran_365 c.iqip##i.onebedroom if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A5") (8) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000279)
				post outputcheck ("A5") (8) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-2.69)
				post outputcheck ("A5") (8) ("One Bedroom") ("Coefficient") (round(r(table)[1,3],.00001)) (.00428)
				post outputcheck ("A5") (8) ("One Bedroom") ("t-stat") (round(r(table)[3,3],.01)) (5.72)
				post outputcheck ("A5") (8) ("Interaction") ("Coefficient") (round(r(table)[1,5],.000001)) (.000165)
				post outputcheck ("A5") (8) ("Interaction") ("t-stat") (round(r(table)[3,5],.01)) (.63)
				post outputcheck ("A5") (8) ("Observations") ("") (e(N)) (502530)
				post outputcheck ("A5") (8) ("Adj. R2") ("") (round(e(r2_a),.001)) (.734)
			
		esttab using output\Table_A5.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		
		eststo clear

			eststo: reghdfe ratlist_90 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A8A") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000407)
				post outputcheck ("A8A") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-2.06)
				post outputcheck ("A8A") (1) ("Observations") ("") (e(N)) (519533)
				post outputcheck ("A8A") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.501)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("A8A") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
		
			eststo: reghdfe ratlist_90_180 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A8A") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000305)
				post outputcheck ("A8A") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.53)
				post outputcheck ("A8A") (2) ("Observations") ("") (e(N)) (518398)
				post outputcheck ("A8A") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.493)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("A8A") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
		
			eststo: reghdfe ratlist_180_270 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A8A") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000144)
				post outputcheck ("A8A") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-.71)
				post outputcheck ("A8A") (3) ("Observations") ("") (e(N)) (517773)
				post outputcheck ("A8A") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.496)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("A8A") (31) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
		
			eststo: reghdfe ratlist_270_365 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A8A") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00000001)) (.00000481)
				post outputcheck ("A8A") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (.03)
				post outputcheck ("A8A") (4) ("Observations") ("") (e(N)) (516489)
				post outputcheck ("A8A") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.508)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("A8A") (4) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)

		esttab using output\Table_A8_A.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)

		eststo clear

			eststo: reghdfe rattran_90 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A8B") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000218)
				post outputcheck ("A8B") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.71)
				post outputcheck ("A8B") (1) ("Observations") ("") (e(N)) (533461)
				post outputcheck ("A8B") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.637)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("A8B") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)

			eststo: reghdfe rattran_90_180 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A8B") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000298)
				post outputcheck ("A8B") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.87)
				post outputcheck ("A8B") (2) ("Observations") ("") (e(N)) (533334)
				post outputcheck ("A8B") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.609)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("A8B") (2) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
		
			eststo: reghdfe rattran_180_270 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A8B") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000366)
				post outputcheck ("A8B") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-2.2)
				post outputcheck ("A8B") (3) ("Observations") ("") (e(N)) (533186)
				post outputcheck ("A8B") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.582)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("A8B") (3) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)
		
			eststo: reghdfe rattran_270_365 iqip if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew trancountfecontrol listcountfecontrol)
				post outputcheck ("A8B") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.000001)) (-.000237)
				post outputcheck ("A8B") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (-1.67)
				post outputcheck ("A8B") (4) ("Observations") ("") (e(N)) (533268)
				post outputcheck ("A8B") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.591)
					local depvar = e(depvar)
					su `depvar' if e(sample)
				post outputcheck ("A8B") (1) ("Dependent Variable Average") ("") (round(r(mean),.01)) (.06)

		esttab using output\Table_A8_B.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)

	*Table 12
		
		use RFSRX_BehavioralMain, clear
		
			eststo clear

				eststo: reghdfe log_olp_resid_b iqip purchaseprice_resid if lpagent==1 & num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("12") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00618)
					post outputcheck ("12") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.91)
					post outputcheck ("12") (1) ("Log Residual Orig Purch Price") ("Coefficient") (round(r(table)[1,2],.001)) (0.122)
					post outputcheck ("12") (1) ("Log Residual Orig Purch Price") ("t-stat") (round(r(table)[3,2],.01)) (18.84)
					post outputcheck ("12") (1) ("Observations") ("") (e(N)) (43658)
					post outputcheck ("12") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.026)
				
				eststo: reghdfe log_olp_resid_b c.iqip##c.purchaseprice_resid if lpagent==1 & num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("12") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00621)
					post outputcheck ("12") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.91)
					post outputcheck ("12") (2) ("Interaction") ("Coefficient") (round(r(table)[1,3],.00001)) (-0.00084)
					post outputcheck ("12") (2) ("Interaction") ("t-stat") (round(r(table)[3,3],.01)) (-.15)
					post outputcheck ("12") (2) ("Log Residual Orig Purch Price") ("Coefficient") (round(r(table)[1,2],.001)) (0.119)
					post outputcheck ("12") (2) ("Log Residual Orig Purch Price") ("t-stat") (round(r(table)[3,2],.01)) (7.61)
					post outputcheck ("12") (2) ("Observations") ("") (e(N)) (43658)
					post outputcheck ("12") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.026)
				
				eststo: reghdfe log_listtopurch iqip logtenureinhome if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("12") (3) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (0.0125)
					post outputcheck ("12") (3) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (2.05)
					post outputcheck ("12") (3) ("Log Tenure in Home") ("Coefficient") (round(r(table)[1,2],.0001)) (0.0359)
					post outputcheck ("12") (3) ("Log Tenure in Home") ("t-stat") (round(r(table)[3,2],.01)) (5.85)
					post outputcheck ("12") (3) ("Observations") ("") (e(N)) (87676)
					post outputcheck ("12") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.038)
				
				eststo: reghdfe listpricechange iqip log_listtopurch if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("12") (4) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00247)
					post outputcheck ("12") (4) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (0.64)
					post outputcheck ("12") (4) ("Log List Price Ratio") ("Coefficient") (round(r(table)[1,2],.0001)) (0.0210)
					post outputcheck ("12") (4) ("Log List Price Ratio") ("t-stat") (round(r(table)[3,2],.01)) (6.16)
					post outputcheck ("12") (4) ("Observations") ("") (e(N)) (85708)
					post outputcheck ("12") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (.042)
				
				eststo: reghdfe listpricechange c.iqip##c.log_listtopurch if num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("12") (5) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.00001)) (0.00493)
					post outputcheck ("12") (5) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.07)
					post outputcheck ("12") (5) ("Interaction") ("Coefficient") (round(r(table)[1,3],.00001)) (-0.00471)
					post outputcheck ("12") (5) ("Interaction") ("t-stat") (round(r(table)[3,3],.01)) (-1.31)
					post outputcheck ("12") (5) ("Log List Price Ratio") ("Coefficient") (round(r(table)[1,2],.00001)) (0.00949)
					post outputcheck ("12") (5) ("Log List Price Ratio") ("t-stat") (round(r(table)[3,2],.01)) (1.05)
					post outputcheck ("12") (5) ("Observations") ("") (e(N)) (85708)
					post outputcheck ("12") (5) ("Adj. R2") ("") (round(e(r2_a),.001)) (.042)
		
			esttab using output\Table_12.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)
		
			eststo clear

				eststo: reghdfe log_olp_resid iqip purchaseprice_resid if lpagent==1 & num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("A7") (1) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (.0255)
					post outputcheck ("A7") (1) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.89)
					post outputcheck ("A7") (1) ("Orig Purch Price, Log Resid") ("Coefficient") (round(r(table)[1,2],.001)) (.179)
					post outputcheck ("A7") (1) ("Orig Purch Price, Log Resid") ("t-stat") (round(r(table)[3,2],.01)) (8.19)
					post outputcheck ("A7") (1) ("Observations") ("") (e(N)) (4689)
					post outputcheck ("A7") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.121)
				
				eststo: reghdfe log_olp_resid c.iqip##c.purchaseprice_resid if lpagent==1 & num==1  & zillowmatched==1 & product<., cluster(county cw) absorb(cm#county totnew)
					post outputcheck ("A7") (2) ("Intermediary Attention") ("Coefficient") (round(r(table)[1,1],.0001)) (.0261)
					post outputcheck ("A7") (2) ("Intermediary Attention") ("t-stat") (round(r(table)[3,1],.01)) (1.87)
					post outputcheck ("A7") (2) ("Orig Purch Price, Log Resid") ("Coefficient") (round(r(table)[1,2],.001)) (.157)
					post outputcheck ("A7") (2) ("Orig Purch Price, Log Resid") ("t-stat") (round(r(table)[3,2],.01)) (2.69)
					post outputcheck ("A7") (2) ("Relevant Interaction") ("Coefficient") (round(r(table)[1,3],.0001)) (-.0076)
					post outputcheck ("A7") (2) ("Relevant Interaction") ("t-stat") (round(r(table)[3,3],.01)) (-.36)
					post outputcheck ("A7") (2) ("Observations") ("") (e(N)) (4689)
					post outputcheck ("A7") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (-.121)
		
			esttab using output\Table_A7.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)

	use RFSRX_ProximateAgentListings, clear
		
		su prop_beds if prop_beds>0 & lp_only_listing==1, de
			post outputcheck ("1B") (.) ("Bedrooms") ("Observations") (r(N)) (2014886)
			post outputcheck ("1B") (.) ("Bedrooms") ("Mean") (round(r(mean),.01)) (3.05)
			post outputcheck ("1B") (.) ("Bedrooms") ("Standard Deviation") (round(r(sd),.01)) (0.98)
			post outputcheck ("1B") (.) ("Bedrooms") ("Q5") (r(p5)) (2)
			post outputcheck ("1B") (.) ("Bedrooms") ("Q25") (r(p25)) (2)
			post outputcheck ("1B") (.) ("Bedrooms") ("Q50") (r(p50)) (3)
			post outputcheck ("1B") (.) ("Bedrooms") ("Q75") (r(p75)) (4)
			post outputcheck ("1B") (.) ("Bedrooms") ("Q95") (r(p95)) (5)
	
		su prop_baths if prop_baths>0 & lp_only_listing==1, de
			post outputcheck ("1B") (.) ("Bathrooms") ("Observations") (r(N)) (1982319)
			post outputcheck ("1B") (.) ("Bathrooms") ("Mean") (round(r(mean),.01)) (2.17)
			post outputcheck ("1B") (.) ("Bathrooms") ("Standard Deviation") (round(r(sd),.01)) (0.78)
			post outputcheck ("1B") (.) ("Bathrooms") ("Q5") (r(p5)) (1)
			post outputcheck ("1B") (.) ("Bathrooms") ("Q25") (r(p25)) (2)
			post outputcheck ("1B") (.) ("Bathrooms") ("Q50") (r(p50)) (2)
			post outputcheck ("1B") (.) ("Bathrooms") ("Q75") (r(p75)) (2.5)
			post outputcheck ("1B") (.) ("Bathrooms") ("Q95") (r(p95)) (3.5)
		
		su w_asmt_sqft_calc if lp_only_listing==1, de
			post outputcheck ("1B") (.) ("Sq Ft") ("Observations") (r(N)) (2429241)
			post outputcheck ("1B") (.) ("Sq Ft") ("Mean") (round(r(mean),.01)) (1815.3)
			post outputcheck ("1B") (.) ("Sq Ft") ("Standard Deviation") (round(r(sd),.01)) (892.13)
			post outputcheck ("1B") (.) ("Sq Ft") ("Q5") (r(p5)) (838)
			post outputcheck ("1B") (.) ("Sq Ft") ("Q25") (r(p25)) (1202)
			post outputcheck ("1B") (.) ("Sq Ft") ("Q50") (r(p50)) (1603)
			post outputcheck ("1B") (.) ("Sq Ft") ("Q75") (r(p75)) (2190)
			post outputcheck ("1B") (.) ("Sq Ft") ("Q95") (r(p95)) (3551)

	use RFSRX_ProximateListings_A, clear
		
		count if beds_diff<.
			post outputcheck ("1C") (.) ("Bedrooms") ("Observations") (r(N)) (475873)
		mean beds_diff
			post outputcheck ("1C") (.) ("Bedrooms") ("Mean") (round(r(table)[1,1],.0001)) (0.0155)
			post outputcheck ("1C") (.) ("Bedrooms") ("t-stat") (round(r(table)[1,1]/r(table)[2,1],.01)) (9.52)
			
		count if baths_diff<.
			post outputcheck ("1C") (.) ("Bathrooms") ("Observations") (r(N)) (475873)
		mean baths_diff
			post outputcheck ("1C") (.) ("Bathrooms") ("Mean") (round(r(table)[1,1],.0001)) (0.0002)
			post outputcheck ("1C") (.) ("Bathrooms") ("t-stat") (round(r(table)[1,1]/r(table)[2,1],.01)) (0.18)
			
		count if sqft_diff<.
			post outputcheck ("1C") (.) ("Sq Ft") ("Observations") (r(N)) (416553)
		mean sqft_diff
			post outputcheck ("1C") (.) ("Sq Ft") ("Mean") (round(r(table)[1,1],.01)) (-29.92)
			post outputcheck ("1C") (.) ("Sq Ft") ("t-stat") (round(r(table)[1,1]/r(table)[2,1],.01)) (-24.45)
			
		count if age_diff<.
			post outputcheck ("1C") (.) ("Building Age") ("Observations") (r(N)) (417757)
		mean age_diff
			post outputcheck ("1C") (.) ("Building Age") ("Mean") (round(r(table)[1,1],.001)) (-1.433)
			post outputcheck ("1C") (.) ("Building Age") ("t-stat") (round(r(table)[1,1]/r(table)[2,1],.01)) (-48.30)

	use RFSRX_ProximateListings_B, clear
			
		count if diffinmean_price<.
			post outputcheck ("1C") (.) ("Sales Price") ("Observations") (r(N)) (307360)
		mean diffinmean_price
			post outputcheck ("1C") (.) ("Sales Price") ("Mean") (round(r(table)[1,1]/1000,.01)) (11.69)
			post outputcheck ("1C") (.) ("Sales Price") ("t-stat") (round(r(table)[1,1]/r(table)[2,1],.01)) (34.98)
			
		count if diffinmean_tom<.
			post outputcheck ("1C") (.) ("Time on Market") ("Observations") (r(N)) (96476)
		mean diffinmean_tom
			post outputcheck ("1C") (.) ("Time on Market") ("Mean") (round(r(table)[1,1],.01)) (46.78)
			post outputcheck ("1C") (.) ("Time on Market") ("t-stat") (round(r(table)[1,1]/r(table)[2,1],.01)) (62.94)
			
	use RFSRX_ProximateListings_C, clear
			
		count if diffinmean_listprice<.
			post outputcheck ("1C") (.) ("Initial List Price") ("Observations") (r(N)) (321246)
		mean diffinmean_listprice
			post outputcheck ("1C") (.) ("Initial List Price") ("Mean") (round(r(table)[1,1]/1000,.01)) (-3.68)
			post outputcheck ("1C") (.) ("Initial List Price") ("t-stat") (round(r(table)[1,1]/r(table)[2,1],.01)) (-12.62)
	
	use RFSRX_AppendixFile_01, clear
	
		eststo clear
			
			eststo: reghdfe log_agent_distance_past redx_agent2, absorb(listyear##listmonth##ams_zip##prop_sqftbuckets##prop_beds prop_beds) cluster(nstate#ams_county listyear#listmonth)
				post outputcheck ("A1") (1) ("Affiliated Agents") ("Coefficient") (round(r(table)[1,1],.001)) (.692)
				post outputcheck ("A1") (1) ("Affiliated Agents") ("t-stat") (round(r(table)[3,1],.01)) (21.68)
				post outputcheck ("A1") (1) ("Observations") ("") (e(N)) (9384901)
				post outputcheck ("A1") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.300)
			
			eststo: reghdfe log_agent_disp_past redx_agent2, absorb(listyear##listmonth##ams_zip##prop_sqftbuckets##prop_beds prop_beds) cluster(nstate#ams_county listyear#listmonth)
				post outputcheck ("A1") (2) ("Affiliated Agents") ("Coefficient") (round(r(table)[1,1],.001)) (1.013)
				post outputcheck ("A1") (2) ("Affiliated Agents") ("t-stat") (round(r(table)[3,1],.01)) (36.46)
				post outputcheck ("A1") (2) ("Observations") ("") (e(N)) (9130570)
				post outputcheck ("A1") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.137)
			
			eststo: reghdfe area_newagent_025 redx_agent2, absorb(listyear##listmonth##ams_zip##prop_sqftbuckets##prop_beds prop_beds) cluster(nstate#ams_county listyear#listmonth)
				post outputcheck ("A1") (3) ("Affiliated Agents") ("Coefficient") (round(r(table)[1,1],.0001)) (-.0497)
				post outputcheck ("A1") (3) ("Affiliated Agents") ("t-stat") (round(r(table)[3,1],.01)) (-14.05)
				post outputcheck ("A1") (3) ("Observations") ("") (e(N)) (10028218)
				post outputcheck ("A1") (3) ("Adj. R2") ("") (round(e(r2_a),.001)) (.39)
			
			eststo: reghdfe agent_avg_lnsaletolist_past redx_agent2, absorb(listyear##listmonth##ams_zip##prop_sqftbuckets##prop_beds prop_beds) cluster(nstate#ams_county listyear#listmonth)
				post outputcheck ("A1") (4) ("Affiliated Agents") ("Coefficient") (round(r(table)[1,1],.00001)) (.00387)
				post outputcheck ("A1") (4) ("Affiliated Agents") ("t-stat") (round(r(table)[3,1],.01)) (0.49)
				post outputcheck ("A1") (4) ("Observations") ("") (e(N)) (7965085)
				post outputcheck ("A1") (4) ("Adj. R2") ("") (round(e(r2_a),.001)) (0.586)
			
			eststo: ppmlhdfe agent_listcount_validloc_past redx_agent2, absorb(listyear##listmonth##ams_zip##prop_sqftbuckets##prop_beds prop_beds) cluster(nstate#ams_county listyear#listmonth)
				post outputcheck ("A1") (5) ("Affiliated Agents") ("Coefficient") (round(r(table)[1,1],.001)) (1.51)
				post outputcheck ("A1") (5) ("Affiliated Agents") ("t-stat") (round(r(table)[3,1],.01)) (33.30)
				post outputcheck ("A1") (5) ("Observations") ("") (e(N)) (10011195)
				post outputcheck ("A1") (5) ("Adj. R2") ("") (round(e(r2_p),.001)) (.730)
			
		esttab using output\Table_A1.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)	
	
	
	use RFSRX_ListingPlatformQuickSaleAnalysis, clear
		
	
		eststo clear
			
			eststo: reghdfe qs rx_listing, noabsorb cluster(fips lp_list_year#lp_list_month)
				post outputcheck ("A2") (1) ("Listing Ever a Lead") ("Coefficient") (round(r(table)[1,1],.0001)) (-.1157)
				post outputcheck ("A2") (1) ("Listing Ever a Lead") ("t-stat") (round(r(table)[3,1],.01)) (-4.90)
				post outputcheck ("A2") (1) ("Observations") ("") (e(N)) (10016380)
				post outputcheck ("A2") (1) ("Adj. R2") ("") (round(e(r2_a),.001)) (.005)
			
			eststo: reghdfe qs rx_listing, absorb(prop_beds##prop_sqftbuckets##lp_list_year##lp_list_month##propertyzip) cluster(fips lp_list_year#lp_list_month)
				post outputcheck ("A2") (2) ("Listing Ever a Lead") ("Coefficient") (round(r(table)[1,1],.0001)) (-.0146)
				post outputcheck ("A2") (2) ("Listing Ever a Lead") ("t-stat") (round(r(table)[3,1],.01)) (-3.93)
				post outputcheck ("A2") (2) ("Observations") ("") (e(N)) (3651082)
				post outputcheck ("A2") (2) ("Adj. R2") ("") (round(e(r2_a),.001)) (.229)
			
		esttab using output\Table_A2.tex, r2 ar2 replace starlevels(* 0.10 ** 0.05 *** 0.01)	
	
	
	
	postclose outputcheck
			
		use output\outputcheck, clear
			gen double diff = value - papervalue
			tostring value, gen(svalue) force
			tostring papervalue, gen(spapervalue) force
			
			bro if svalue!=spapervalue